|
1 gICommentForm = null ; |
|
2 |
|
3 instanciateICommentForm = function() { |
|
4 gICommentForm = { |
|
5 'position':[CY.WidgetPositionExt.LC, CY.WidgetPositionExt.LC], |
|
6 'formId':CY.guid(), |
|
7 'formTitleId':CY.guid(), |
|
8 'titleInputId':CY.guid(), |
|
9 'contentInputId':CY.guid(), |
|
10 'tagsInputId':CY.guid(), |
|
11 'formatInputId':CY.guid(), |
|
12 'startWrapperInputId':CY.guid(), |
|
13 'endWrapperInputId':CY.guid(), |
|
14 'startOffsetInputId':CY.guid(), |
|
15 'endOffsetInputId':CY.guid(), |
|
16 'selectionPlaceId':CY.guid(), |
|
17 'keyId':CY.guid(), |
|
18 'currentSelId':CY.guid(), |
|
19 'currentSelIdI':CY.guid(), |
|
20 'addBtnId':CY.guid(), |
|
21 'cancelBtnId':CY.guid(), |
|
22 'closeBtnId':CY.guid() |
|
23 } ; |
|
24 |
|
25 if (!sv_loggedIn) { |
|
26 gICommentForm ['nameInputId'] = CY.guid() ; |
|
27 gICommentForm ['emailInputId'] = CY.guid() ; |
|
28 } |
|
29 |
|
30 var overlayHtml = getHtml(gICommentForm) ; |
|
31 |
|
32 var width = gLayout.getTopICommentsWidth() ; |
|
33 |
|
34 var overlay = new CY.Overlay( { |
|
35 zIndex :3, |
|
36 shim :false, // until we really need it, no shim |
|
37 visible :false, |
|
38 headerContent :overlayHtml['headerContent'], |
|
39 bodyContent :overlayHtml['bodyContent'], |
|
40 xy :[10,10], |
|
41 width : width |
|
42 }); |
|
43 overlay.get('contentBox').addClass("c-newcomment") ; |
|
44 |
|
45 // attach to DOM |
|
46 overlay.render('#leftcolumn'); |
|
47 |
|
48 if (!sv_loggedIn) { |
|
49 CY.get("#"+gICommentForm['nameInputId']).set('value',gPrefs.get("user","name")) ; |
|
50 CY.get("#"+gICommentForm['emailInputId']).set('value',gPrefs.get("user","email")) ; |
|
51 } |
|
52 |
|
53 CY.get("#"+gICommentForm['formTitleId']).set('innerHTML', gettext('New comment')) ; |
|
54 CY.get("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ; |
|
55 |
|
56 CY.on("click", onSubmitICommentFormClick, "#"+gICommentForm['addBtnId']); |
|
57 CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['cancelBtnId']); |
|
58 CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['closeBtnId']); |
|
59 |
|
60 gICommentForm['overlay'] = overlay ; |
|
61 |
|
62 var animationHide = null ; |
|
63 animationHide = new CY.Anim({ |
|
64 node: overlay.get('boundingBox'), |
|
65 duration: .3, //gPrefs['general']['animduration'], |
|
66 easing: CY.Easing.easeOut |
|
67 }); |
|
68 gICommentForm['animationHide'] = animationHide ; |
|
69 animationHide.set('to', { opacity: 0});// height : 0 doesn't work |
|
70 gICommentForm['animationHide-handle'] = animationHide.on('end', onICommentFormHideAnimEnd, gICommentForm); |
|
71 |
|
72 var animationShow = null ; |
|
73 animationShow = new CY.Anim({ |
|
74 node: overlay.get('boundingBox'), |
|
75 duration: .3, //gPrefs['general']['animduration'], |
|
76 easing: CY.Easing.easeOut |
|
77 }); |
|
78 gICommentForm['animationShow'] = animationShow ; |
|
79 animationShow.set('to', { opacity: 1}); |
|
80 gICommentForm['animationShow-handle'] = animationShow.on('end', onICommentFormShowAnimEnd, gICommentForm); |
|
81 |
|
82 changeFormFieldsWidth(gICommentForm['formId'], width) ; |
|
83 } |
|
84 |
|
85 cleanICommentForm = function() { |
|
86 CY.get("#"+gICommentForm['currentSelIdI']).set('innerHTML', gNoSelectionYet) ; |
|
87 |
|
88 var hostNode = gICommentForm['overlay'].getStdModNode(CY.WidgetStdMod.BODY) ; |
|
89 hostNode.queryAll(".comment_input").set('value', "") ; |
|
90 |
|
91 CY.get("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ... |
|
92 |
|
93 if (!sv_loggedIn) { |
|
94 hostNode.queryAll(".user_input").set('value', "") ; |
|
95 } |
|
96 } |
|
97 |
|
98 onICommentFormHideAnimEnd = function() { |
|
99 // iComment['overlay'].blur() ; |
|
100 this.overlay.hide() ; |
|
101 gSync.resume() ; |
|
102 } |
|
103 |
|
104 onICommentFormShowAnimEnd = function() { |
|
105 gSync.resume() ; |
|
106 } |
|
107 |
|
108 onSubmitICommentFormClick = function() { |
|
109 if (!sv_loggedIn) { |
|
110 var name = CY.get("#"+gICommentForm['nameInputId']).get('value') ; |
|
111 gPrefs.persist("user", "name", name) ; |
|
112 |
|
113 var email = CY.get("#"+gICommentForm['emailInputId']).get('value') ; |
|
114 gPrefs.persist("user", "email", email) ; |
|
115 } |
|
116 gSync.saveComment(gICommentForm['formId']) ; |
|
117 } |
|
118 |
|
119 onCancelICommentFormClick = function() { |
|
120 gSync.cancelICommentForm() ; |
|
121 } |
|
122 |
|
123 // record selection info in hidden form fields |
|
124 _updateICommentFormSelection = function(ids, displayedText, csStartSelection, csEndSelection) { |
|
125 var node = CY.Node.get('#'+ids['currentSelIdI']) ; |
|
126 if (node != null) |
|
127 node.set('innerHTML', displayedText) ; |
|
128 |
|
129 node = CY.get('#'+ids['startWrapperInputId']) ; |
|
130 if (node != null) |
|
131 node.set('value', csStartSelection['elt'].id.substring("sv_".length)) ; |
|
132 node = CY.get('#'+ids['startOffsetInputId']) ; |
|
133 if (node != null) |
|
134 node.set('value', csStartSelection['offset']) ; |
|
135 node = CY.get('#'+ids['endWrapperInputId']) ; |
|
136 if (node != null) |
|
137 node.set('value', csEndSelection['elt'].id.substring("sv_".length)) ; |
|
138 node = CY.get('#'+ids['endOffsetInputId']) ; |
|
139 if (node != null) |
|
140 node.set('value', csEndSelection['offset']) ; |
|
141 } |
|
142 |
|
143 updateICommentFormSelection = function(selection) { |
|
144 var text = (selection == null) ? "" : selection['text'] ; |
|
145 if (text != "") { |
|
146 // display text to be commented |
|
147 var displayedText = text ; |
|
148 var maxLength = 100 ; // even number only |
|
149 if (text.length > maxLength ) { |
|
150 var start = text.substring(0, (text.substring(0, maxLength/2)).lastIndexOf(" ")) ; |
|
151 var endPart = text.substring(text.length - maxLength/2) ; |
|
152 var end = endPart.substring(endPart.indexOf(" ")) ; |
|
153 displayedText = start + " ... " + end ; |
|
154 } |
|
155 var csStartSelection = _convertSelectionFromCCToCS(selection['start']) ; |
|
156 var csEndSelection = _convertSelectionFromCCToCS(selection['end']) ; |
|
157 |
|
158 _updateICommentFormSelection(gICommentForm, displayedText, csStartSelection, csEndSelection); |
|
159 if (gEdit != null) |
|
160 _updateICommentFormSelection(gEdit['ids'], displayedText, csStartSelection, csEndSelection); |
|
161 positionICommentForm() ; |
|
162 } |
|
163 } |
|
164 |
|
165 showICommentForm= function () { |
|
166 removeFormErrMsg(gICommentForm['formId']) ; |
|
167 if (!sv_loggedIn) { |
|
168 if (CY.get("#"+gICommentForm['nameInputId']).get('value') == '') |
|
169 CY.get("#"+gICommentForm['nameInputId']).set('value', gPrefs.get('user','name')) ; |
|
170 if (CY.get("#"+gICommentForm['emailInputId']).get('value') == '') |
|
171 CY.get("#"+gICommentForm['emailInputId']).set('value', gPrefs.get('user','email')) ; |
|
172 } |
|
173 gIComments.hide() ; |
|
174 positionICommentForm() ; |
|
175 gICommentForm['overlay'].show() ; |
|
176 CY.get("#"+gICommentForm['titleInputId']).focus() ; |
|
177 } |
|
178 |
|
179 isICommentFormVisible = function () { |
|
180 if (gICommentForm != null) |
|
181 return gICommentForm['overlay'].get('visible') ; |
|
182 return false ; |
|
183 } |
|
184 |
|
185 positionICommentForm = function () { |
|
186 if (gICommentForm != null) { |
|
187 var overlay = gICommentForm['overlay'] ; |
|
188 var boundingBox = overlay.get('boundingBox') ; |
|
189 |
|
190 var commentFormHeight = boundingBox.get('offsetHeight') ; |
|
191 var windowHeight = boundingBox.get('winHeight') ; |
|
192 |
|
193 var pos = gICommentForm['position'] ; |
|
194 if (commentFormHeight > windowHeight) // trying to have save comment visible ... : |
|
195 pos = [CY.WidgetPositionExt.BL, CY.WidgetPositionExt.BL] ; |
|
196 |
|
197 overlay.set("align", {points:pos}); |
|
198 boundingBox.setX(boundingBox.getX() + gConf['iCommentLeftPadding']); |
|
199 } |
|
200 } |