@@ -997,6 +997,7 @@ $(function () {
997997 bookmarkModalGroupTpl : $ ( '.bookmark-modal script[data-template="repoGroup"]' ) . html ( ) ,
998998 bookmarkModalGroupItemTpl : $ ( '.bookmark-modal script[data-template="groupItem"]' ) . html ( ) ,
999999 bookmarkModalTagItemTpl : $ ( '.bookmark-modal script[data-template="tagItem"]' ) . html ( ) ,
1000+ bookmarkModalTagDotTpl : $ ( '.bookmark-modal script[data-template="tagDot"]' ) . html ( ) ,
10001001 bookmarkModalReopTpl : $ ( '.bookmark-modal script[data-template="repoItem"]' ) . html ( ) ,
10011002
10021003 bookmarkUserModal : $ ( '.bookmark-user-modal' ) ,
@@ -1078,7 +1079,9 @@ $(function () {
10781079 } ) ;
10791080 els . bookmarkModalContent . on ( 'click' , '.group-menu .add-repo' , beforeAddRepoToGroup ) ;
10801081 els . bookmarkModalContent . on ( 'click' , '.tag-menu .add-repo' , beforeAddRepoToTag ) ;
1082+ els . bookmarkModalContent . on ( 'click' , '.repo-item .group-menu' , renderBookmarkRepoGroupMenu ) ;
10811083 els . bookmarkModalContent . on ( 'click' , '.repo-item .tag-menu' , renderBookmarkRepoTagMenu ) ;
1084+ els . bookmarkModalContent . on ( 'mouseenter mouseleave' , '.repo-item' , renderBookmarkRepoTagDots ) ;
10821085 els . bookmarkModalContent . on ( 'keyup' , '.repo-group-item>.hd .search input' , renderBookmarkSearchRepos ) ;
10831086 els . bookmarkModalContent . on ( 'click' , '.repo-group-item>.hd .search submit' , renderBookmarkSearchRepos ) ;
10841087 els . bookmarkUserModal . on ( 'click' , '.submit' , function ( ) {
@@ -1560,6 +1563,7 @@ $(function () {
15601563 els . bookmarkModalContent . find ( '.repo-group-item:last-child .collapse' ) . addClass ( 'in' ) ;
15611564 } , 100 ) ;
15621565
1566+ updateBookmarkGroupsData ( ) ;
15631567 renderBookmarkTagMenu ( allTagHtm ) ;
15641568 renderBookmarkUsers ( data . users ) ;
15651569 }
@@ -1583,6 +1587,14 @@ $(function () {
15831587 } ) ;
15841588 }
15851589
1590+ function renderBookmarkRepoGroupMenu ( ) {
1591+ var el = $ ( this ) ,
1592+ id = el . parents ( '.repo-item' ) . attr ( 'data-repoid' ) ;
1593+ els . lastBookmarkGroupsData . forEach ( function ( key ) {
1594+ el . find ( '.add-repo[data-id="' + key . id + '"]' ) [ key . repoIds . indexOf ( id ) == - 1 ?'removeAttr' :'attr' ] ( 'data-selected' , true ) ;
1595+ } ) ;
1596+ }
1597+
15861598 function renderBookmarkTagMenu ( htm ) {
15871599 els . bookmarkModalTagMenu . find ( '.add-repo' ) . remove ( ) ;
15881600 els . bookmarkModalTagMenu . append ( htm ) ;
@@ -1593,9 +1605,28 @@ $(function () {
15931605 var el = $ ( this ) ,
15941606 id = el . parents ( '.repo-item' ) . attr ( 'data-repoid' ) ;
15951607 els . lastBookmarkTagsData . forEach ( function ( key ) {
1596- el . find ( '.add-repo[data-id="' + key . id + '"]' ) [ key . repoIds . indexOf ( id ) == - 1 ?'removeAttr' :'attr' ] ( 'data-tagged ' , true ) ;
1608+ el . find ( '.add-repo[data-id="' + key . id + '"]' ) [ key . repoIds . indexOf ( id ) == - 1 ?'removeAttr' :'attr' ] ( 'data-selected ' , true ) ;
15971609 } ) ;
15981610 }
1611+ function renderBookmarkRepoTagDots ( e ) {
1612+ var el = $ ( this ) ,
1613+ id = el . attr ( 'data-repoid' ) ,
1614+ dotsEl = el . find ( '.tag-dots' ) ,
1615+ htm = [ ] ;
1616+ if ( e . type == 'mouseenter' ) {
1617+ els . lastBookmarkTagsData . forEach ( function ( key ) {
1618+ if ( key . repoIds . indexOf ( id ) != - 1 ) {
1619+ htm . push (
1620+ els . bookmarkModalTagDotTpl
1621+ . replace ( / \{ c o l o r \} / g, key . color )
1622+ ) ;
1623+ }
1624+ } ) ;
1625+ dotsEl . html ( htm . join ( '' ) ) . addClass ( 'in' ) ;
1626+ } else {
1627+ dotsEl . html ( '' ) . removeClass ( 'in' ) ;
1628+ }
1629+ }
15991630
16001631 function renderBookmarkSearchRepos ( ) {
16011632 var gEl = els . bookmarkModalContent . find ( '.repo-group-item[data-id="0"]' ) ,
@@ -1702,6 +1733,7 @@ $(function () {
17021733 function beforeAddRepoToGroup ( ) {
17031734 var el = $ ( this ) ,
17041735 targetGroupId = el . attr ( 'data-id' ) ,
1736+ selected = el . attr ( 'data-selected' ) ,
17051737 repoEl = el . parents ( '.repo-item' ) ,
17061738 repoId = repoEl . attr ( 'data-repoid' ) ,
17071739 repoUrl = repoEl . find ( '.repo-item__hd a' ) . attr ( 'href' ) ,
@@ -1713,33 +1745,38 @@ $(function () {
17131745 targetGroupName = targetGoupEl . find ( '>.hd>a' ) . html ( ) ,
17141746 targetGoupCountEl = targetGoupEl . find ( '.hd>.count' ) ,
17151747 targetGoupCountNum = parseInt ( targetGoupCountEl . html ( ) || 0 ) ,
1716- targetGroupHasRepo = targetGoupEl . find ( '.repo-item[data-repoid="' + repoId + '"]' ) . length ;
1748+ targetGroupRepo = targetGoupEl . find ( '.repo-item[data-repoid="' + repoId + '"]' ) ;
17171749
1718- if ( targetGroupId != undefined && targetGroupId != 0 ) {
1750+ if ( ! selected ) {
17191751 bookmarkModel . RepoGroupTable . addRopoId ( targetGroupId , repoId ) ;
17201752
1721- if ( ! targetGroupHasRepo ) {
1753+ if ( ! targetGroupRepo . length ) {
17221754 targetGoupCountEl . html ( ++ targetGoupCountNum ) ;
17231755 targetGoupEl . find ( '.repo-list' ) . append ( repoEl . clone ( ) ) ;
17241756 }
17251757 els . isGithub && DDMSModel . postBookmarkGroup ( repoId , repoUrl , targetGroupName ) ;
17261758
1727- } else if ( curGroupId != 0 ) {
1728- bookmarkModel . RepoGroupTable . removeRopoId ( curGroupId , repoId ) ;
1759+ } else {
1760+ bookmarkModel . RepoGroupTable . removeRopoId ( targetGroupId , repoId ) ;
17291761
1730- curGroupElCountEl . html ( -- curGoupCountNum || '' ) ;
1731- repoEl . remove ( ) ;
1762+ if ( targetGroupId == curGroupId ) {
1763+ repoEl . remove ( ) ;
1764+ curGroupElCountEl . html ( -- curGoupCountNum || '' ) ;
1765+ } else {
1766+ targetGroupRepo . remove ( ) ;
1767+ targetGoupCountEl . html ( -- targetGoupCountNum || '' ) ;
1768+ }
17321769 }
17331770 }
17341771 function beforeAddRepoToTag ( ) {
17351772 var el = $ ( this ) ,
17361773 targetId = el . attr ( 'data-id' ) ,
1737- tagged = el . attr ( 'data-tagged ' ) ,
1774+ selected = el . attr ( 'data-selected ' ) ,
17381775 repoEl = el . parents ( '.repo-item' ) ,
17391776 repoId = repoEl . attr ( 'data-repoid' ) ;
17401777
17411778 if ( targetId != undefined && targetId != 0 ) {
1742- bookmarkModel . RepoTagTable [ tagged ?'removeRopoId' :'addRopoId' ] ( targetId , repoId ) ;
1779+ bookmarkModel . RepoTagTable [ selected ?'removeRopoId' :'addRopoId' ] ( targetId , repoId ) ;
17431780 }
17441781 }
17451782
@@ -1770,6 +1807,11 @@ $(function () {
17701807 els . lastBookmarkTagsData = res ;
17711808 } ) ;
17721809 }
1810+ function updateBookmarkGroupsData ( ) {
1811+ bookmarkModel . RepoGroupTable . getAll ( function ( res ) {
1812+ els . lastBookmarkGroupsData = res ;
1813+ } ) ;
1814+ }
17731815
17741816 init ( ) ;
17751817 //end view and render
0 commit comments