@@ -473,15 +473,15 @@ $(function () {
473473 . exec ( ) . then ( function ( res ) {
474474 curUser = res [ 0 ] ;
475475 callback && callback ( ) ;
476- win . trigger ( 'DB:Table.User.onchange' , { type : DBEventType . C , result : res } ) ;
476+ win . trigger ( 'DB:Table.User.onchange' , { type : DBEventType . C } ) ;
477477 } ) ;
478478 } ) ;
479479 }
480480
481481 this . updateSync = function ( name ) {
482482 DB . update ( Tables . User ) . set ( Tables . User . lastSync , new Date ( ) ) . where ( Tables . User . name . eq ( name ) )
483483 . exec ( ) . then ( function ( res ) {
484- win . trigger ( 'DB:Table.User.onchange' , { type : DBEventType . U , result : res } ) ;
484+ win . trigger ( 'DB:Table.User.onchange' , { type : DBEventType . U } ) ;
485485 } ) ;
486486 }
487487
@@ -495,7 +495,7 @@ $(function () {
495495 . where ( Tables . User . id . eq ( id ) )
496496 . exec ( ) . then ( function ( res ) {
497497 callback && callback ( res ) ;
498- win . trigger ( 'DB:Table.User.onchange' , { type : DBEventType . D , result : res } ) ;
498+ win . trigger ( 'DB:Table.User.onchange' , { type : DBEventType . D } ) ;
499499 } ) ;
500500 } ) ;
501501 }
@@ -525,7 +525,7 @@ $(function () {
525525 . exec ( ) . then ( function ( rows ) {
526526 ! rows . length && DB . insertOrReplace ( ) . into ( Tables . RepoGroup ) . values ( [ row ] )
527527 . exec ( ) . then ( function ( res ) {
528- win . trigger ( 'DB:Table.RepoGroup.onchange' , { type : DBEventType . C , result : res } ) ;
528+ win . trigger ( 'DB:Table.RepoGroup.onchange' , { type : DBEventType . C } ) ;
529529 } ) ;
530530 } ) ;
531531 }
@@ -540,9 +540,7 @@ $(function () {
540540 }
541541 ids = ids . length ? ids . join ( ',' ) : '' ;
542542 DB . update ( Tables . RepoGroup ) . set ( Tables . RepoGroup . repoIds , ids ) . where ( Tables . RepoGroup . id . eq ( id ) )
543- . exec ( ) . then ( function ( res ) {
544- win . trigger ( 'DB:Table.RepoGroup.onchange' , { type : DBEventType . U , result : res } ) ;
545- } ) ;
543+ . exec ( ) ;
546544 }
547545 } ) ;
548546 }
@@ -559,20 +557,24 @@ $(function () {
559557 }
560558 ids = ids . length ? ids . join ( ',' ) : '' ;
561559 DB . update ( Tables . RepoGroup ) . set ( Tables . RepoGroup . repoIds , ids ) . where ( Tables . RepoGroup . id . eq ( id ) )
562- . exec ( ) . then ( function ( res ) {
563- win . trigger ( 'DB:Table.RepoGroup.onchange' , { type : DBEventType . U , result : res } ) ;
564- } ) ;
560+ . exec ( ) ;
565561 }
566562 } ) ;
567563 }
564+ this . updateName = function ( id , name ) {
565+ DB . update ( Tables . RepoGroup ) . set ( Tables . RepoGroup . name , name ) . where ( Tables . RepoGroup . id . eq ( id ) )
566+ . exec ( ) . then ( function ( ) {
567+ win . trigger ( 'DB:Table.RepoGroup.onchange' , { type : DBEventType . U , fields : 'name' } ) ;
568+ } ) ;
569+ }
568570
569571 this . delete = function ( id , callback ) {
570572 DB . delete ( )
571573 . from ( Tables . RepoGroup )
572574 . where ( Tables . RepoGroup . id . eq ( id ) )
573575 . exec ( ) . then ( function ( res ) {
574576 callback && callback ( res ) ;
575- win . trigger ( 'DB:Table.RepoGroup.onchange' , { type : DBEventType . D , result : res } ) ;
577+ win . trigger ( 'DB:Table.RepoGroup.onchange' , { type : DBEventType . D } ) ;
576578 } ) ;
577579 }
578580
@@ -627,7 +629,7 @@ $(function () {
627629 . where ( Tables . Repo . id . eq ( id ) )
628630 . exec ( ) . then ( function ( res ) {
629631 callback && callback ( res ) ;
630- win . trigger ( 'DB:Table.Repo.onchange' , { type : DBEventType . D , result : res } ) ;
632+ win . trigger ( 'DB:Table.Repo.onchange' , { type : DBEventType . D } ) ;
631633 } ) ;
632634 }
633635
@@ -637,7 +639,7 @@ $(function () {
637639 . where ( Tables . Repo . userId . eq ( id ) )
638640 . exec ( ) . then ( function ( res ) {
639641 callback && callback ( res ) ;
640- win . trigger ( 'DB:Table.Repo.onchange' , { type : DBEventType . D , result : res } ) ;
642+ win . trigger ( 'DB:Table.Repo.onchange' , { type : DBEventType . D } ) ;
641643 } ) ;
642644 }
643645
@@ -825,6 +827,7 @@ $(function () {
825827 bookmarkUserModalUserTpl : $ ( '.bookmark-user-modal .user-list script' ) . html ( ) ,
826828
827829 bookmarkGroupModal : $ ( '.bookmark-group-modal' ) ,
830+ bookmarkGroupModalInput : $ ( '.bookmark-group-modal input' ) ,
828831
829832 githubCorner : $ ( '.github-corner svg' ) ,
830833 donate : $ ( '.donate' ) ,
@@ -862,12 +865,12 @@ $(function () {
862865
863866 //bookmark
864867 els . win . on ( 'DB:ready' , renderBookmarkGroup ) ;
865- els . win . on ( 'DB:Table.RepoGroup.onchange' , function ( e , data ) {
866- data && data . type != 'UPDATED' && renderBookmarkGroup ( ) ;
867- } ) ;
868+ els . win . on ( 'DB:Table.RepoGroup.onchange' , renderBookmarkGroup ) ;
868869 els . bookmarkBtn . on ( 'click' , showBookmark ) ;
869870 els . bookmarkModal . on ( 'click' , '.add-account' , showBookmarkUserModal ) ;
870- els . bookmarkModal . on ( 'click' , '.add-group' , showBookmarkGroupModal ) ;
871+ els . bookmarkModal . on ( 'click' , '.add-group' , function ( ) {
872+ showBookmarkGroupModal ( ) ;
873+ } ) ;
871874 els . bookmarkModalContentHd . on ( 'click' , '.submit' , function ( ) {
872875 beforeAddBookmarkUser ( els . bookmarkModalContentHd ) ;
873876 } ) ;
@@ -886,8 +889,11 @@ $(function () {
886889 return false ;
887890 }
888891 } ) ;
889- els . bookmarkGroupModal . on ( 'click' , '.submit' , beforeAddBookmarkGroup ) ;
892+ els . bookmarkGroupModal . on ( 'click' , '.submit' , beforeEditBookmarkGroup ) ;
890893 els . bookmarkModalContent . on ( 'click' , '.repo-group-item>.hd .ctrl .del' , beforeDelBookmarkGroup ) ;
894+ els . bookmarkModalContent . on ( 'click' , '.repo-group-item>.hd .ctrl .edit' , function ( ) {
895+ showBookmarkGroupModal ( this . dataset . id , this . dataset . name ) ;
896+ } ) ;
891897 els . bookmarkModalContent . on ( 'click' , '.dropdown-item' , beforeAddRepoToGroup ) ;
892898 els . bookmarkModalContent . on ( 'keyup' , '.repo-group-item>.hd .search input' , renderBookmarkSearchRepos ) ;
893899 els . bookmarkModalContent . on ( 'click' , '.repo-group-item>.hd .search submit' , renderBookmarkSearchRepos ) ;
@@ -933,9 +939,14 @@ $(function () {
933939 els . bookmarkUserModal . modal ( 'show' ) ;
934940 }
935941
936- function showBookmarkGroupModal ( ) {
942+ function showBookmarkGroupModal ( id , name ) {
937943 hideBookmark ( ) ;
938944 els . bookmarkGroupModal . modal ( 'show' ) ;
945+ if ( id ) {
946+ els . bookmarkGroupModalInput . attr ( 'data-id' , id ) . val ( name || '' ) ;
947+ } else {
948+ els . bookmarkGroupModalInput . removeAttr ( 'data-id' ) . val ( '' ) ;
949+ }
939950 }
940951
941952 function onLocationHashChanged ( e ) {
@@ -1085,6 +1096,7 @@ $(function () {
10851096 . replace ( / \{ i d \} / g, repo . id )
10861097 . replace ( / \{ o r i g i n R e p o I d \} / g, repo . originRepoId )
10871098 . replace ( / \{ f u l l _ n a m e \} / g, repo . data . full_name )
1099+ . replace ( / \{ _ f u l l _ n a m e \} / g, repo . data . full_name . toLowerCase ( ) )
10881100 . replace ( / \{ d e s c r i p t i o n \} / g, repo . data . description || '' )
10891101 . replace ( / \{ h t m l _ u r l \} / g, repo . data . html_url )
10901102 . replace ( / \{ g r o u p I t e m s \} / g, allGroupHtm )
@@ -1346,7 +1358,7 @@ $(function () {
13461358 var gEl = els . bookmarkModalContent . find ( '.repo-group-item[data-id="0"]' ) ,
13471359 inputEl = gEl . find ( '.hd .search input' ) ,
13481360 countEl = gEl . find ( '.hd .count' ) ,
1349- val = inputEl . val ( ) . trim ( ) ,
1361+ val = inputEl . val ( ) . trim ( ) . toLowerCase ( ) ,
13501362 repoEls = gEl . find ( '.repo-list .repo-item' ) ,
13511363 matchRepoEls = gEl . find ( '.repo-list .repo-item[data-name*="' + val + '"]' ) ,
13521364 resultRepoEls = val . length ?matchRepoEls :repoEls ;
@@ -1418,10 +1430,18 @@ $(function () {
14181430 inputEl . val ( '' ) ;
14191431 }
14201432
1421- function beforeAddBookmarkGroup ( ) {
1422- els . bookmarkGroupModalInput = els . bookmarkGroupModalInput || els . bookmarkGroupModal . find ( 'input' ) ;
1423- var val = els . bookmarkGroupModal . find ( 'input' ) . val ( ) . trim ( ) ;
1424- val . length && bookmarkModel . RepoGroupTable . add ( val ) ;
1433+ function beforeEditBookmarkGroup ( ) {
1434+ var id = els . bookmarkGroupModalInput . attr ( 'data-id' ) ,
1435+ val = els . bookmarkGroupModalInput . val ( ) . trim ( ) ;
1436+
1437+ if ( val . length ) {
1438+ if ( id ) {
1439+ bookmarkModel . RepoGroupTable . updateName ( id , val ) ;
1440+ els . bookmarkGroupModalInput . removeAttr ( 'data-id' ) ;
1441+ } else {
1442+ bookmarkModel . RepoGroupTable . add ( val ) ;
1443+ }
1444+ }
14251445 els . bookmarkGroupModalInput . val ( '' ) ;
14261446 }
14271447
0 commit comments