|
0
|
1 |
gICommentForm = null ; |
|
|
2 |
|
|
|
3 |
instanciateICommentForm = function() { |
|
341
|
4 |
gICommentForm = { |
|
382
|
5 |
'position':[CY.WidgetPositionExt.TL, CY.WidgetPositionExt.TL], |
|
341
|
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({ |
|
0
|
64 |
node: overlay.get('boundingBox'), |
|
|
65 |
duration: .3, //gPrefs['general']['animduration'], |
|
|
66 |
easing: CY.Easing.easeOut |
|
341
|
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); |
|
0
|
71 |
|
|
341
|
72 |
var animationShow = null ; |
|
|
73 |
animationShow = new CY.Anim({ |
|
0
|
74 |
node: overlay.get('boundingBox'), |
|
|
75 |
duration: .3, //gPrefs['general']['animduration'], |
|
|
76 |
easing: CY.Easing.easeOut |
|
341
|
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) ; |
|
0
|
83 |
} |
|
|
84 |
|
|
|
85 |
cleanICommentForm = function() { |
|
341
|
86 |
CY.get("#"+gICommentForm['currentSelIdI']).set('innerHTML', gNoSelectionYet) ; |
|
0
|
87 |
|
|
|
88 |
var hostNode = gICommentForm['overlay'].getStdModNode(CY.WidgetStdMod.BODY) ; |
|
|
89 |
hostNode.queryAll(".comment_input").set('value', "") ; |
|
341
|
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 |
} |
|
0
|
96 |
} |
|
|
97 |
|
|
|
98 |
onICommentFormHideAnimEnd = function() { |
|
341
|
99 |
// iComment['overlay'].blur() ; |
|
|
100 |
this.overlay.hide() ; |
|
|
101 |
gSync.resume() ; |
|
0
|
102 |
} |
|
|
103 |
|
|
|
104 |
onICommentFormShowAnimEnd = function() { |
|
341
|
105 |
gSync.resume() ; |
|
0
|
106 |
} |
|
|
107 |
|
|
|
108 |
onSubmitICommentFormClick = function() { |
|
341
|
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']) ; |
|
0
|
117 |
} |
|
|
118 |
|
|
|
119 |
onCancelICommentFormClick = function() { |
|
341
|
120 |
gSync.cancelICommentForm() ; |
|
0
|
121 |
} |
|
|
122 |
|
|
|
123 |
// record selection info in hidden form fields |
|
|
124 |
_updateICommentFormSelection = function(ids, displayedText, csStartSelection, csEndSelection) { |
|
341
|
125 |
var node = CY.Node.get('#'+ids['currentSelIdI']) ; |
|
|
126 |
if (node != null) |
|
|
127 |
node.set('innerHTML', displayedText) ; |
|
|
128 |
|
|
0
|
129 |
node = CY.get('#'+ids['startWrapperInputId']) ; |
|
341
|
130 |
if (node != null) |
|
|
131 |
node.set('value', csStartSelection['elt'].id.substring("sv_".length)) ; |
|
0
|
132 |
node = CY.get('#'+ids['startOffsetInputId']) ; |
|
341
|
133 |
if (node != null) |
|
|
134 |
node.set('value', csStartSelection['offset']) ; |
|
0
|
135 |
node = CY.get('#'+ids['endWrapperInputId']) ; |
|
341
|
136 |
if (node != null) |
|
|
137 |
node.set('value', csEndSelection['elt'].id.substring("sv_".length)) ; |
|
0
|
138 |
node = CY.get('#'+ids['endOffsetInputId']) ; |
|
341
|
139 |
if (node != null) |
|
|
140 |
node.set('value', csEndSelection['offset']) ; |
|
0
|
141 |
} |
|
|
142 |
|
|
|
143 |
updateICommentFormSelection = function(selection) { |
|
341
|
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 |
} |
|
0
|
155 |
var csStartSelection = _convertSelectionFromCCToCS(selection['start']) ; |
|
|
156 |
var csEndSelection = _convertSelectionFromCCToCS(selection['end']) ; |
|
|
157 |
|
|
|
158 |
_updateICommentFormSelection(gICommentForm, displayedText, csStartSelection, csEndSelection); |
|
|
159 |
if (gEdit != null) |
|
341
|
160 |
_updateICommentFormSelection(gEdit['ids'], displayedText, csStartSelection, csEndSelection); |
|
|
161 |
positionICommentForm() ; |
|
|
162 |
} |
|
0
|
163 |
} |
|
|
164 |
|
|
|
165 |
showICommentForm= function () { |
|
341
|
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() ; |
|
0
|
177 |
} |
|
|
178 |
|
|
|
179 |
isICommentFormVisible = function () { |
|
341
|
180 |
if (gICommentForm != null) |
|
|
181 |
return gICommentForm['overlay'].get('visible') ; |
|
|
182 |
return false ; |
|
0
|
183 |
} |
|
|
184 |
|
|
|
185 |
positionICommentForm = function () { |
|
341
|
186 |
if (gICommentForm != null) { |
|
|
187 |
var overlay = gICommentForm['overlay'] ; |
|
|
188 |
var boundingBox = overlay.get('boundingBox') ; |
|
0
|
189 |
|
|
341
|
190 |
var commentFormHeight = boundingBox.get('offsetHeight') ; |
|
|
191 |
var windowHeight = boundingBox.get('winHeight') ; |
|
0
|
192 |
|
|
341
|
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}); |
|
382
|
198 |
if (commentFormHeight <= windowHeight) |
|
|
199 |
overlay.set("y", overlay.get("y") + 30); |
|
341
|
200 |
boundingBox.setX(boundingBox.getX() + gConf['iCommentLeftPadding']); |
|
|
201 |
} |
|
|
202 |
} |