1- // view=manage
2- // notes opened
3- // _______________________________________
4- // | username - note title - note date | SCROLL
5- // | users online |
6- // | total users |
7- // |[close note][view note] |
8- // |______________________________________|
9- //
10- // create note
11- // _______________________________
12- // | |
13- // | reference |
14- // | title |
15- // | record |
16- // | [GO]|
17- // |_______________________________|
18- //
19- // view=interact¬e=id&start=id
20- //
21- // reference: url
22- // talk :
23- // ______________________
24- // |user did that at 0000|
25- // |content |
26- // |reply |
27- // |_____________________|
28- //
1+
292Class . define ( "AppNotes" , {
303 from : [ "WithDOMElements2" ] ,
314 ctor : function ( ) {
@@ -87,14 +60,12 @@ Class.define("AppNotes",{
8760 function refresh_notes ( ) {
8861 Import ( { url :"/notes/listRoot" , method :"post" , data :{ } } )
8962 . done ( function ( data ) {
90- //alert("/notes/listRoot\r\n" + data);
9163 data = JSON . parse ( data ) ;
9264 if ( data . result ) {
9365 p . $ . dir . elementsClear ( ) ;
9466 for ( var x = 0 ; x < data . value . length ; x ++ ) {
9567 var p2 = p . $ . dir . elementPushPacket (
9668 "<div style='background-color:white;color:black;border:solid 1px #000;padding:20px;margin-bottom:10px;'>" +
97- // "<div>id : "+data.value[x].id+"</div>"+
9869 "<div>title : " + data . value [ x ] . title + "</div>" +
9970 "<div>reference : " + data . value [ x ] . reference + "</div>" +
10071 "<div style='display:flex;width:100%;'><input type='button' id='btnCloseNote' value='close this notes'/><input type='button' id='btnViewNote' value='view notes'/></div>" +
@@ -113,7 +84,7 @@ Class.define("AppNotes",{
11384 reference : p . el . txtNoteReference . value
11485 } } )
11586 . done ( function ( data ) {
116- alert ( "/note/create\r\n" + data ) ;
87+
11788 data = JSON . parse ( data ) ;
11889 refresh_notes ( ) ;
11990
@@ -129,29 +100,23 @@ Class.define("AppNotes",{
129100
130101 "<div id='app_notes' style='border:solid 1px #fff;overflow:auto;background-color:white;'>" +
131102 "<div style='padding:10px;margin:10px;border:solid 1px #000;'>" +
132- /*
133- "<div style='display:flex'>"+
134- "<div id='btnTXT' style='background-color:black;color:white;border-radius:5px;padding:5px;margin:5px;'>TXT</div>"+
135- "<div id='btnRTF' style='background-color:black;color:white;border-radius:5px;padding:5px;margin:5px;'>RTF</div>"+
136- "<div id='btnCANVAS' style='background-color:black;color:white;border-radius:5px;padding:5px;margin:5px;'>CANVAS</div>" +
137- "<div id='btnMIC' style='background-color:black;color:white;border-radius:5px;padding:5px;margin:5px;'>MIC</div>" +
138- "<div id='btnCAM' style='background-color:black;color:white;border-radius:5px;padding:5px;margin:5px;'>CAM</div>" +
139- "<div id='btnFILE' style='background-color:black;color:white;border-radius:5px;padding:5px;margin:5px;'>FILE</div>" +
140- "</div>"+
141- */
142- "<div style='display:flex;margin-bottom:10px;'>" +
143- "<textarea id='txtMessage' style='flex:1;height:60px;'></textarea>" +
144- "<input id='btnSend' type='button' value='send' style='height:67px;'/>" +
145- "</div>" +
146103 "<div>" +
147104 "<div>Title : <span id='lblTitle' style='font-size:30px;'></span></div>" +
148105 "<div>Reference : <span id='lblReference' style='font-weight:bold;text-decoration:underline;'></span></div>" +
149106 "<br/>" +
150- "<WithDOMElements2 id='dir'></WithDOMElements2>" +
107+ "<div style='display:flex;margin-bottom:10px;'>" + // sender control
108+ "<textarea id='txtMessage' style='flex:1;height:60px;'></textarea>" +
109+ "<input id='btnSend' type='button' value='send' style='height:67px;'/>" +
110+ "</div>" +
111+ "<br/>" +
112+ "<WithDOMElements2 id='dir'>" +
113+
114+ "</WithDOMElements2>" +
151115 "</div>" +
152116 "</div>" +
153117 "</div>"
154118 ) ;
119+
155120 this . holder = p ;
156121 var app = {
157122 loaded : false
@@ -161,39 +126,30 @@ Class.define("AppNotes",{
161126 alert ( "must have an id to access interact." ) ;
162127 return ;
163128 }
164- p . el . btnSend . addEventListener ( "click" , function ( ) {
165-
166- var str = p . el . txtMessage . value ;
167- var dict = { 0 : "0" , 1 : "1" , 2 : "2" , 3 : "3" , 4 : "4" , 5 : "5" , 6 : "6" , 7 : "7" , 8 : "8" , 9 : "9" , 10 : "A" , 11 : "B" , 12 : "C" , 13 : "D" , 14 : "E" , 15 : "F" } ;
168- var sb = [ ] ;
169- for ( var x = 0 ; x < str . length ; x ++ ) {
170- var code = str . charCodeAt ( x ) ;
171- sb . push ( dict [ ( 0xF0 & code ) >> 4 ] + dict [ 0xF & code ] ) ;
172- }
173-
174- Import ( { url :"/notes/push" , method :"post" , data : { id : context . args . id , message : sb . join ( "" ) } } )
129+ function Send ( id , path , str , done , error ) {
130+ var args = { id : id , message : Export . Codec . Hex ( str ) } ;
131+ if ( path ) args . path = path ;
132+ Import ( { url :"/notes/push" , method :"post" , data : args } )
175133 . done ( function ( data ) {
176- p . el . txtMessage . value = "" ;
177134 data = JSON . parse ( data ) ;
178135 if ( data . result ) {
179- refresh_notes ( ) ;
136+ done && done ( data ) ;
137+ } else {
138+ error & error ( data ) ;
180139 }
181140 } )
182141 . send ( ) ;
142+ }
143+ p . el . btnSend . addEventListener ( "click" , function ( ) {
144+ Send ( context . args . id , null , p . el . txtMessage . value , function ( ) {
145+ p . el . txtMessage . value = "" ;
146+ refresh_notes ( ) ;
147+ } , function ( data ) {
148+ alert ( error + "\r\n" + JSON . stringify ( data ) ) ;
149+ p . el . txtMessage . value = "" ;
150+ } )
183151 } ) ;
184- function setReply ( p , item , id , path ) {
185- /*
186- p.el.btnInsert.style.backgroundColor = "#ccc";
187- p.el.btnInsert.style.height = "2px";
188- p.el.btnInsert.addEventListener("mouseover",function() {
189- p.el.btnInsert.style.backgroundColor = "red";
190-
191- });
192- p.el.btnInsert.addEventListener("mouseout",function() {
193- p.el.btnInsert.style.backgroundColor = "#ccc";
194-
195- });
196- */
152+ function setReply ( p , id , path ) {
197153 p . el . btnReply . addEventListener ( "click" , function ( ) {
198154 var p2 = p . $ . reply_control . elementSetPacket (
199155 "<div style='display:flex;margin-bottom:10px;'>" +
@@ -202,33 +158,12 @@ Class.define("AppNotes",{
202158 "</div>"
203159 ) ;
204160 p2 . el . btnSend . addEventListener ( "click" , function ( ) {
205- var str = p2 . el . txtMessage . value ;
206- var dict = { 0 : "0" , 1 : "1" , 2 : "2" , 3 : "3" , 4 : "4" , 5 : "5" , 6 : "6" , 7 : "7" , 8 : "8" , 9 : "9" , 10 : "A" , 11 : "B" , 12 : "C" , 13 : "D" , 14 : "E" , 15 : "F" } ;
207- var sb = [ ] ;
208- for ( var x = 0 ; x < str . length ; x ++ ) {
209- var code = str . charCodeAt ( x ) ;
210- sb . push ( dict [ ( 0xF0 & code ) >> 4 ] + dict [ 0xF & code ] ) ;
211- }
212-
213- Import ( {
214- url :"/notes/push" ,
215- method :"post" ,
216- data : {
217- id : id ,
218- message : sb . join ( "" ) ,
219- path : path
220- }
221- } )
222- . done ( function ( data ) {
223- data = JSON . parse ( data ) ;
224- if ( data . result ) {
225- refresh_notes ( ) ;
226- }
161+ Send ( id , path , p2 . el . txtMessage . value , function ( ) {
162+ refresh_notes ( ) ;
163+ } , function ( data ) {
164+ alert ( error + "\r\n" + JSON . stringify ( data ) ) ;
227165 } )
228- . send ( ) ;
229-
230166 p . $ . reply_control . elementsClear ( ) ;
231-
232167 } ) ;
233168 } ) ;
234169 p . el . btnClose . addEventListener ( "click" , function ( ) {
@@ -276,7 +211,7 @@ Class.define("AppNotes",{
276211 "<div id='btnInsert'>" +
277212 "</div>"
278213 )
279- setReply ( p3 , arr [ x ] , id , JSON . stringify ( path ) ) ;
214+ setReply ( p3 , id , JSON . stringify ( path ) ) ;
280215 fill_replies ( p3 , arr [ x ] . replies , id , JSON . stringify ( path ) ) ;
281216 }
282217 path . pop ( ) ;
@@ -285,50 +220,22 @@ Class.define("AppNotes",{
285220 function refresh_notes ( ) {
286221 Import ( { url :"/notes/list" , method :"post" , data :{ id :context . args . id } } )
287222 . done ( function ( data ) {
288-
289223 data = JSON . parse ( data ) ;
290224 if ( data . result ) {
291225 app . version = data . version ;
292226 app . id = context . args . id ;
293227 p . $ . lblTitle . elementSetPacket ( data . title ) ;
294228 p . $ . lblReference . elementSetPacket ( data . reference ) ;
295-
296229 var arr = data . value ;
297230 p . $ . dir . elementsClear ( ) ;
298-
299- for ( var x = 0 ; x < arr . length ; x ++ ) {
300- console . log ( "--------------------------------------------------------------------------" ) ;
301- if ( arr [ x ] . enabled ) {
302- ( function ( x ) {
303- var path = [ x ] ;
304- var date = new Date ( arr [ x ] . date ) ;
305- var date_str = date . getDate ( ) + "/" + date . getMonth ( ) + "/" + date . getFullYear ( ) + " " + date . getHours ( ) + ":" + date . getMinutes ( ) ;
306- var p2 = p . $ . dir . elementUnshiftPacket (
307- "<div style='flex:1;background-color:white;color:black;padding-left:10px;'>" +
308- "<div style='font-size:12px;'>" +
309- "<span>" + JSON . stringify ( path ) + ":</span>" +
310- "<span style='font-weight:bold;'>" + arr [ x ] . user + "</span>" +
311- "<span> at </span>" +
312- "<span style='font-weight:bold;'>" + date_str + "</span>" +
313- "<span> | </span>" +
314- "<span id='btnReply' style='font-family:Courier New;font-size:12px;'> Reply </span>" +
315- "<span> | </span>" +
316- "<span id='btnClose' style='font-family:Courier New;font-size:12px;'> Close </span>" +
317- "</div>" +
318- "<div style='font-size:16px;'>" + arr [ x ] . message . value + "</div>" +
319- "<WithDOMElements2 id='reply_control'></WithDOMElements2>" +
320- "<WithDOMElements2 id='reply_area'></WithDOMElements2>" +
321- "</div>" +
322- "<div id='btnInsert'>" +
323- "</div>"
324- )
325- setReply ( p2 , arr [ x ] , context . args . id , JSON . stringify ( [ x ] ) ) ;
326- fill_replies ( p2 , arr [ x ] . replies , context . args . id , JSON . stringify ( [ x ] ) ) ;
327- } ) ( x ) ;
328- }
329- }
231+ var p2 = p . $ . dir . elementPushPacket (
232+ "<WithDOMElements2 id='reply_area'></WithDOMElements2>"
233+ )
234+ p . $ . dir . $ = {
235+ reply_area : p2 . $ . reply_area ,
236+ } ;
237+ fill_replies ( p . $ . dir , arr , context . args . id , JSON . stringify ( [ ] ) ) ;
330238 app . loaded = true ;
331-
332239 } else {
333240 alert ( JSON . stringify ( data ) ) ;
334241 }
@@ -353,14 +260,13 @@ Class.define("AppNotes",{
353260 }
354261 } , 2000 ) ;
355262 }
263+ service ( ) ;
264+
356265 }
357-
358266
359-
360267 this . hide = function ( ) {
361268 self . components . $ . app_notes_manage . elementsClear ( ) ;
362269 self . components . $ . app_notes_interact . elementsClear ( ) ;
363- //p.el.app_notes.style.display = "none";
364270 }
365271 this . show = function ( context ) {
366272
@@ -370,8 +276,6 @@ Class.define("AppNotes",{
370276 load_interact ( ) ;
371277 }
372278
373- //alert(JSON.stringify(context.notes)+JSON.stringify(context.args));
374- //p.el.app_notes.style.display = "";
375279 }
376280 this . show ( context ) ;
377281
0 commit comments