1 gICommentForm = null ; |
1 gICommentForm = null ; |
2 |
2 |
3 instanciateICommentForm = function() { |
3 instanciateICommentForm = function() { |
4 gICommentForm = { |
4 gICommentForm = { |
5 'position':[CY.WidgetPositionAlign.TL, CY.WidgetPositionAlign.TL], |
5 'position':[CY.WidgetPositionExt.TL, CY.WidgetPositionExt.TL], |
6 'formId':CY.guid(), |
6 'formId':CY.guid(), |
7 'formTitleId':CY.guid(), |
7 'formTitleId':CY.guid(), |
8 'titleInputId':CY.guid(), |
8 'titleInputId':CY.guid(), |
9 'contentInputId':CY.guid(), |
9 'contentInputId':CY.guid(), |
10 'tagsInputId':CY.guid(), |
10 'tagsInputId':CY.guid(), |
45 |
45 |
46 // attach to DOM |
46 // attach to DOM |
47 overlay.render('#leftcolumn'); |
47 overlay.render('#leftcolumn'); |
48 |
48 |
49 if (!sv_loggedIn) { |
49 if (!sv_loggedIn) { |
50 CY.one("#"+gICommentForm['nameInputId']).set('value',gPrefs.get("user","name")) ; |
50 CY.get("#"+gICommentForm['nameInputId']).set('value',gPrefs.get("user","name")) ; |
51 CY.one("#"+gICommentForm['emailInputId']).set('value',gPrefs.get("user","email")) ; |
51 CY.get("#"+gICommentForm['emailInputId']).set('value',gPrefs.get("user","email")) ; |
52 } |
52 } |
53 |
53 |
54 CY.one("#"+gICommentForm['formTitleId']).set('innerHTML', gettext('New comment')) ; |
54 CY.get("#"+gICommentForm['formTitleId']).set('innerHTML', gettext('New comment')) ; |
55 CY.one("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ; |
55 CY.get("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ; |
56 |
56 |
57 CY.on("click", onSubmitICommentFormClick, "#"+gICommentForm['addBtnId']); |
57 CY.on("click", onSubmitICommentFormClick, "#"+gICommentForm['addBtnId']); |
58 CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['cancelBtnId']); |
58 CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['cancelBtnId']); |
59 CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['closeBtnId']); |
59 CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['closeBtnId']); |
60 |
60 |
82 |
82 |
83 changeFormFieldsWidth(gICommentForm['formId'], width) ; |
83 changeFormFieldsWidth(gICommentForm['formId'], width) ; |
84 } |
84 } |
85 |
85 |
86 cleanICommentForm = function() { |
86 cleanICommentForm = function() { |
87 CY.one("#"+gICommentForm['currentSelIdI']).set('innerHTML', gNoSelectionYet) ; |
87 CY.get("#"+gICommentForm['currentSelIdI']).set('innerHTML', gNoSelectionYet) ; |
88 |
88 |
89 var hostNode = gICommentForm['overlay'].getStdModNode(CY.WidgetStdMod.BODY) ; |
89 var hostNode = gICommentForm['overlay'].getStdModNode(CY.WidgetStdMod.BODY) ; |
90 hostNode.all(".comment_input").set('value', "") ; |
90 hostNode.queryAll(".comment_input").set('value', "") ; |
91 |
91 |
92 CY.one("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ... |
92 CY.get("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ... |
93 |
93 |
94 if (!sv_loggedIn) { |
94 if (!sv_loggedIn) { |
95 hostNode.all(".user_input").set('value', "") ; |
95 hostNode.queryAll(".user_input").set('value', "") ; |
96 } |
96 } |
97 } |
97 } |
98 |
98 |
99 onICommentFormHideAnimEnd = function() { |
99 onICommentFormHideAnimEnd = function() { |
100 // iComment['overlay'].blur() ; |
100 // iComment['overlay'].blur() ; |
106 gSync.resume() ; |
106 gSync.resume() ; |
107 } |
107 } |
108 |
108 |
109 onSubmitICommentFormClick = function() { |
109 onSubmitICommentFormClick = function() { |
110 if (!sv_loggedIn) { |
110 if (!sv_loggedIn) { |
111 var name = CY.one("#"+gICommentForm['nameInputId']).get('value') ; |
111 var name = CY.get("#"+gICommentForm['nameInputId']).get('value') ; |
112 gPrefs.persist("user", "name", name) ; |
112 gPrefs.persist("user", "name", name) ; |
113 |
113 |
114 var email = CY.one("#"+gICommentForm['emailInputId']).get('value') ; |
114 var email = CY.get("#"+gICommentForm['emailInputId']).get('value') ; |
115 gPrefs.persist("user", "email", email) ; |
115 gPrefs.persist("user", "email", email) ; |
116 } |
116 } |
117 gSync.saveComment(gICommentForm['formId']) ; |
117 gSync.saveComment(gICommentForm['formId']) ; |
118 } |
118 } |
119 |
119 |
121 gSync.cancelICommentForm() ; |
121 gSync.cancelICommentForm() ; |
122 } |
122 } |
123 |
123 |
124 // record selection info in hidden form fields |
124 // record selection info in hidden form fields |
125 _updateICommentFormSelection = function(ids, displayedText, csStartSelection, csEndSelection) { |
125 _updateICommentFormSelection = function(ids, displayedText, csStartSelection, csEndSelection) { |
126 var node = CY.Node.one('#'+ids['currentSelIdI']) ; |
126 var node = CY.Node.get('#'+ids['currentSelIdI']) ; |
127 if (node != null) |
127 if (node != null) |
128 node.set('innerHTML', displayedText) ; |
128 node.set('innerHTML', displayedText) ; |
129 |
129 |
130 node = CY.one('#'+ids['startWrapperInputId']) ; |
130 node = CY.get('#'+ids['startWrapperInputId']) ; |
131 if (node != null) |
131 if (node != null) |
132 node.set('value', csStartSelection['elt'].id.substring("sv_".length)) ; |
132 node.set('value', csStartSelection['elt'].id.substring("sv_".length)) ; |
133 node = CY.one('#'+ids['startOffsetInputId']) ; |
133 node = CY.get('#'+ids['startOffsetInputId']) ; |
134 if (node != null) |
134 if (node != null) |
135 node.set('value', csStartSelection['offset']) ; |
135 node.set('value', csStartSelection['offset']) ; |
136 node = CY.one('#'+ids['endWrapperInputId']) ; |
136 node = CY.get('#'+ids['endWrapperInputId']) ; |
137 if (node != null) |
137 if (node != null) |
138 node.set('value', csEndSelection['elt'].id.substring("sv_".length)) ; |
138 node.set('value', csEndSelection['elt'].id.substring("sv_".length)) ; |
139 node = CY.one('#'+ids['endOffsetInputId']) ; |
139 node = CY.get('#'+ids['endOffsetInputId']) ; |
140 if (node != null) |
140 if (node != null) |
141 node.set('value', csEndSelection['offset']) ; |
141 node.set('value', csEndSelection['offset']) ; |
142 } |
142 } |
143 |
143 |
144 updateICommentFormSelection = function(selection) { |
144 updateICommentFormSelection = function(selection) { |
164 } |
164 } |
165 |
165 |
166 showICommentForm= function () { |
166 showICommentForm= function () { |
167 removeFormErrMsg(gICommentForm['formId']) ; |
167 removeFormErrMsg(gICommentForm['formId']) ; |
168 if (!sv_loggedIn) { |
168 if (!sv_loggedIn) { |
169 if (CY.one("#"+gICommentForm['nameInputId']).get('value') == '') |
169 if (CY.get("#"+gICommentForm['nameInputId']).get('value') == '') |
170 CY.one("#"+gICommentForm['nameInputId']).set('value', gPrefs.get('user','name')) ; |
170 CY.get("#"+gICommentForm['nameInputId']).set('value', gPrefs.get('user','name')) ; |
171 if (CY.one("#"+gICommentForm['emailInputId']).get('value') == '') |
171 if (CY.get("#"+gICommentForm['emailInputId']).get('value') == '') |
172 CY.one("#"+gICommentForm['emailInputId']).set('value', gPrefs.get('user','email')) ; |
172 CY.get("#"+gICommentForm['emailInputId']).set('value', gPrefs.get('user','email')) ; |
173 } |
173 } |
174 gIComments.hide() ; |
174 gIComments.hide() ; |
175 hideToc(); |
175 hideToc(); |
176 positionICommentForm() ; |
176 positionICommentForm() ; |
177 gICommentForm['overlay'].show() ; |
177 gICommentForm['overlay'].show() ; |
178 CY.one("#"+gICommentForm['titleInputId']).focus() ; |
178 CY.get("#"+gICommentForm['titleInputId']).focus() ; |
179 } |
179 } |
180 |
180 |
181 isICommentFormVisible = function () { |
181 isICommentFormVisible = function () { |
182 if (gICommentForm != null) |
182 if (gICommentForm != null) |
183 return gICommentForm['overlay'].get('visible') ; |
183 return gICommentForm['overlay'].get('visible') ; |
192 var commentFormHeight = boundingBox.get('offsetHeight') ; |
192 var commentFormHeight = boundingBox.get('offsetHeight') ; |
193 var windowHeight = boundingBox.get('winHeight') ; |
193 var windowHeight = boundingBox.get('winHeight') ; |
194 |
194 |
195 var pos = gICommentForm['position'] ; |
195 var pos = gICommentForm['position'] ; |
196 if (commentFormHeight > windowHeight) // trying to have save comment visible ... : |
196 if (commentFormHeight > windowHeight) // trying to have save comment visible ... : |
197 pos = [CY.WidgetPositionAlign.BL, CY.WidgetPositionAlign.BL] ; |
197 pos = [CY.WidgetPositionExt.BL, CY.WidgetPositionExt.BL] ; |
198 |
198 |
199 overlay.set("align", {points:pos}); |
199 overlay.set("align", {points:pos}); |
200 if (commentFormHeight <= windowHeight) |
200 if (commentFormHeight <= windowHeight) |
201 overlay.set("y", overlay.get("y") + 30); |
201 overlay.set("y", overlay.get("y") + 30); |
202 boundingBox.setX(boundingBox.getX() + gConf['iCommentLeftPadding']); |
202 boundingBox.setX(boundingBox.getX() + gConf['iCommentLeftPadding']); |