1+ var collections = ( function ( ) {
2+
3+ var self = new nModule ( ) ;
4+
5+ var essenses = { } ;
6+
7+ var Essense = function ( p ) {
8+
9+ var mid = p . mid
10+
11+ var primary = deep ( p , 'history' ) ;
12+
13+ var el , ed , author = { } ;
14+
15+ var actions = {
16+ newcollection : function ( ) {
17+ self . app . platform . sdk . collections . opennewcollectionwindow ( )
18+ } ,
19+
20+ loadcollections : function ( clbk ) {
21+ self . app . platform . sdk . collections . load . profile ( author . address , ( r ) => {
22+
23+ var collections = r . contents
24+
25+ if ( clbk ) clbk ( collections )
26+ } , ed . count )
27+ }
28+ }
29+
30+ var events = {
31+
32+ }
33+
34+ var renders = {
35+ collectionsdata : function ( items = [ ] , clbk ) {
36+ self . shell ( {
37+ name : 'collectionsdata' ,
38+ el : el . c . find ( '.collectionsdata' ) ,
39+ data : {
40+ items : items ,
41+ } ,
42+ insertimmediately : true ,
43+ } , function ( p ) {
44+ if ( items . length ) {
45+ el . c . addClass ( '.hasitems' )
46+ }
47+
48+ if ( clbk ) clbk ( )
49+ } )
50+ }
51+ }
52+
53+ var state = {
54+ save : function ( ) {
55+
56+ } ,
57+ load : function ( ) {
58+
59+ }
60+ }
61+
62+ var initEvents = function ( ) {
63+
64+ el . c . find ( '.newcollection' ) . on ( 'click' , function ( ) {
65+ actions . newcollection ( )
66+ } )
67+
68+ self . app . psdk . updatelisteners [ mid ] = self . app . platform . actionListeners [ mid ] = function ( { type, alias, status} ) {
69+
70+ if ( type == 'collection' ) {
71+ if ( author . address == alias . actor ) {
72+ make ( )
73+ }
74+
75+ }
76+
77+ }
78+ }
79+
80+ var make = function ( clbk ) {
81+
82+ actions . loadcollections ( collections => {
83+ renders . collectionsdata ( collections , clbk )
84+ } )
85+
86+ }
87+
88+ return {
89+ primary : primary ,
90+
91+ id : mid ,
92+
93+ getdata : function ( clbk , p ) {
94+
95+ ed = p . settings . essenseData
96+
97+ if ( ! ed . count ) ed . count = 6
98+
99+ if ( ed . count > 100 ) ed . count = 100
100+
101+ var data = {
102+ ed
103+ } ;
104+
105+ author = { }
106+
107+ author . address = ed . address
108+
109+ self . sdk . users . get ( author . address , function ( ) {
110+
111+ author . data = self . psdk . userInfo . get ( author . address )
112+ author . me = self . app . user . isItMe ( author . address )
113+ author . reputationBlocked = self . app . platform . sdk . user . reputationBlocked ( author . address )
114+
115+ data . author = author
116+
117+ clbk ( data ) ;
118+
119+ } )
120+
121+ } ,
122+
123+ destroy : function ( ) {
124+ ed = { }
125+ el = { } ;
126+
127+ delete self . app . platform . actionListeners [ mid ]
128+ delete self . app . psdk . updatelisteners [ mid ]
129+ } ,
130+
131+ init : function ( p ) {
132+
133+ state . load ( ) ;
134+
135+ el = { } ;
136+ el . c = p . el . find ( '#' + self . map . id ) ;
137+
138+ initEvents ( ) ;
139+
140+ make ( )
141+
142+ p . clbk ( null , p ) ;
143+ }
144+ }
145+ } ;
146+
147+
148+
149+ self . run = function ( p ) {
150+
151+ var essense = self . addEssense ( essenses , Essense , p ) ;
152+
153+ self . init ( essense , p ) ;
154+
155+ } ;
156+
157+ self . stop = function ( ) {
158+
159+ _ . each ( essenses , function ( essense ) {
160+
161+ window . rifticker . add ( ( ) => {
162+ essense . destroy ( ) ;
163+ } )
164+
165+ } )
166+
167+ }
168+
169+ return self ;
170+ } ) ( ) ;
171+
172+
173+ if ( typeof module != "undefined" )
174+ {
175+ module . exports = collections ;
176+ }
177+ else {
178+
179+ app . modules . collections = { } ;
180+ app . modules . collections . module = collections ;
181+
182+ }
0 commit comments