|
1 gEditICommentHost = null ; |
|
2 gEdit = null ; |
|
3 |
|
4 dbgc = null ; |
|
5 showEditForm = function(iCommentHost) { |
|
6 |
|
7 if (gEdit == null) { |
|
8 gEdit = { |
|
9 'ids':{ |
|
10 'formId':CY.guid(), |
|
11 'formTitleId':CY.guid(), |
|
12 'nameInputId':CY.guid(), |
|
13 'emailInputId':CY.guid(), |
|
14 'titleInputId':CY.guid(), |
|
15 'contentInputId':CY.guid(), |
|
16 'tagsInputId':CY.guid(), |
|
17 'formatInputId':CY.guid(), |
|
18 'startWrapperInputId':CY.guid(), |
|
19 'endWrapperInputId':CY.guid(), |
|
20 'startOffsetInputId':CY.guid(), |
|
21 'endOffsetInputId':CY.guid(), |
|
22 'changeScopeInputId':CY.guid(), |
|
23 'changeScopeInputWrapper':CY.guid(), |
|
24 'selectionPlaceId':CY.guid(), |
|
25 'keyId':CY.guid(), |
|
26 'editCommentId':CY.guid(), |
|
27 'currentSelId':CY.guid(), |
|
28 'currentSelIdI':CY.guid(), |
|
29 'addBtnId':CY.guid(), |
|
30 'cancelBtnId':CY.guid() |
|
31 }, |
|
32 'handlers':{} |
|
33 } ; |
|
34 } |
|
35 |
|
36 gEditICommentHost = iCommentHost ; |
|
37 |
|
38 gEditICommentHost.hideContent() ; |
|
39 |
|
40 // FORM HTML |
|
41 var overlayHtml = getHtml(gEdit['ids']) ; |
|
42 var editHeader = '<div class="icomment-edit-header">' + overlayHtml['headerContent'] + '</div>' ; |
|
43 var editBody = '<div class="icomment-edit-body">' + overlayHtml['bodyContent'] + '</div>' ; |
|
44 |
|
45 // cf. http://yuilibrary.com/projects/yui3/ticket/2528319 |
|
46 gEditICommentHost['overlay'].setStdModContent(CY.WidgetStdMod.HEADER,CY.Node.create(editHeader),CY.WidgetStdMod.AFTER); |
|
47 gEditICommentHost['overlay'].setStdModContent(CY.WidgetStdMod.BODY,CY.Node.create(editBody),CY.WidgetStdMod.AFTER); |
|
48 |
|
49 // FORM TITLE |
|
50 CY.get("#"+gEdit['ids']['formTitleId']).set('innerHTML', gettext("Edit comment")) ; |
|
51 |
|
52 // FETCH FORM VALUES FROM COMMENT |
|
53 |
|
54 var comment = gDb.getComment(gEditICommentHost.commentId) ; |
|
55 CY.get("#"+gEdit['ids']['editCommentId']).set('value', comment.id) ; |
|
56 CY.get("#"+gEdit['ids']['keyId']).set('value', comment.key) ; |
|
57 |
|
58 CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").set('checked', false) ; |
|
59 if (comment.reply_to_id != null) |
|
60 CY.get("#"+gEdit['ids']['changeScopeInputId']).addClass('displaynone') |
|
61 changeScopeFormClick() ; // to adapt |
|
62 |
|
63 CY.get("#"+gEdit['ids']['nameInputId']).set('value', comment.name) ; |
|
64 CY.get("#"+gEdit['ids']['emailInputId']).set('value', comment.email) ; |
|
65 |
|
66 if (comment.logged_author) { |
|
67 CY.get("#"+gEdit['ids']['nameInputId']).setAttribute("disabled", true); |
|
68 CY.get("#"+gEdit['ids']['emailInputId']).setAttribute("disabled", true); |
|
69 } |
|
70 |
|
71 // FORM VALUES |
|
72 CY.get("#"+gEdit['ids']['titleInputId']).set('value', comment['title']) ; |
|
73 CY.get("#"+gEdit['ids']['contentInputId']).set('value', comment['content']) ; |
|
74 CY.get("#"+gEdit['ids']['tagsInputId']).set('value', comment['tags']) ; |
|
75 |
|
76 CY.get("#"+gEdit['ids']['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ... |
|
77 |
|
78 // WIDTH |
|
79 var width = gLayout.getTopICommentsWidth() ; |
|
80 changeFormFieldsWidth(gEdit['ids']['formId'], width) ; |
|
81 |
|
82 // ATTACH EVENT HANDLERS |
|
83 gEdit['handlers']['addBtnId'] = CY.on("click", onEditSaveClick, "#"+gEdit['ids']['addBtnId']); |
|
84 gEdit['handlers']['cancelBtnId'] = CY.on("click", onEditCancelClick, "#"+gEdit['ids']['cancelBtnId']); |
|
85 gEdit['handlers']['changeScope'] = CY.on("click", onChangeScopeClick, "#"+gEdit['ids']['changeScopeInputId']); |
|
86 |
|
87 } |
|
88 onEditSaveClick = function(iCommentHost) { |
|
89 if (readyForAction()) |
|
90 gSync.editComment() ; |
|
91 } |
|
92 onEditCancelClick = function(iCommentHost) { |
|
93 if (readyForAction()) |
|
94 gSync.cancelEdit() ; |
|
95 } |
|
96 onChangeScopeClick = function() { |
|
97 if (readyForAction()) |
|
98 gSync.changeScopeFormClick() ; |
|
99 } |
|
100 changeScopeFormClick = function() { |
|
101 var node = CY.get("#"+gEdit['ids']['currentSelId']) ; |
|
102 if (CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked')) |
|
103 node.removeClass('displaynone') ; |
|
104 else |
|
105 node.addClass('displaynone') ; |
|
106 } |
|
107 cancelEditForm = function() { |
|
108 if (gEditICommentHost != null) { |
|
109 // DETACH EVENT HANDLERS |
|
110 for (var id in gEdit['handlers']) { |
|
111 if (gEdit['handlers'][id] != null) { |
|
112 gEdit['handlers'][id].detach() ; |
|
113 gEdit['handlers'][id] = null ; |
|
114 } |
|
115 } |
|
116 |
|
117 // REMOVE EDIT FORM NODES FROM ICOMMENT OVERLAY |
|
118 var node = gEditICommentHost['overlay'].get('contentBox').query(".icomment-edit-body") ; |
|
119 node.get('parentNode').removeChild(node) ; |
|
120 node = gEditICommentHost['overlay'].get('contentBox').query(".icomment-edit-header") ; |
|
121 node.get('parentNode').removeChild(node) ; |
|
122 |
|
123 // SHOW ICOMMENT OVERLAY |
|
124 gEditICommentHost.showContent() ; |
|
125 |
|
126 gEditICommentHost = null ; |
|
127 } |
|
128 } |