author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Wed, 07 Apr 2010 11:56:30 +0200 | |
branch | stable |
changeset 5171 | 1c2567af37dd |
parent 4901 | 19ecbbc4f633 |
child 5453 | d0c8076e298b |
child 5767 | 1d811df051c2 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* :organization: Logilab |
|
3 |
* :copyright: 2003-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
4 |
* :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
5 |
* |
|
6 |
* |
|
7 |
*/ |
|
8 |
||
9 |
// widget namespace |
|
10 |
Widgets = {}; |
|
11 |
||
12 |
||
13 |
/* this function takes a DOM node defining a widget and |
|
14 |
* instantiates / builds the appropriate widget class |
|
15 |
*/ |
|
16 |
function buildWidget(wdgnode) { |
|
17 |
var wdgclass = Widgets[wdgnode.getAttribute('cubicweb:wdgtype')]; |
|
18 |
if (wdgclass) { |
|
19 |
var wdg = new wdgclass(wdgnode); |
|
20 |
} |
|
21 |
} |
|
22 |
||
23 |
/* This function is called on load and is in charge to build |
|
24 |
* JS widgets according to DOM nodes found in the page |
|
25 |
*/ |
|
26 |
function buildWidgets(root) { |
|
27 |
root = root || document; |
|
28 |
jQuery(root).find('.widget').each(function() { |
|
29 |
if (this.getAttribute('cubicweb:loadtype') == 'auto') { |
|
30 |
buildWidget(this); |
|
31 |
} |
|
32 |
}); |
|
33 |
} |
|
34 |
||
35 |
||
36 |
// we need to differenciate cases where initFacetBoxEvents is called |
|
37 |
// with one argument or without any argument. If we use `initFacetBoxEvents` |
|
38 |
// as the direct callback on the jQuery.ready event, jQuery will pass some argument |
|
39 |
// of his, so we use this small anonymous function instead. |
|
40 |
jQuery(document).ready(function() {buildWidgets();}); |
|
41 |
||
42 |
||
43 |
Widgets.SuggestField = defclass('SuggestField', null, { |
|
44 |
__init__: function(node, options) { |
|
45 |
var multi = node.getAttribute('cubicweb:multi') || "no"; |
|
46 |
options = options || {}; |
|
47 |
options.multiple = (multi == "yes") ? true : false; |
|
48 |
var dataurl = node.getAttribute('cubicweb:dataurl'); |
|
49 |
var method = postJSON; |
|
50 |
if (options.method == 'get'){ |
|
51 |
method = function(url, data, callback) { |
|
52 |
// We can't rely on jQuery.getJSON because the server |
|
53 |
// might set the Content-Type's response header to 'text/plain' |
|
54 |
jQuery.get(url, data, function(response) { |
|
55 |
callback(evalJSON(response)); |
|
56 |
}); |
|
57 |
}; |
|
58 |
} |
|
59 |
var self = this; // closure |
|
60 |
method(dataurl, null, function(data) { |
|
61 |
// in case we received a list of couple, we assume that the first |
|
62 |
// element is the real value to be sent, and the second one is the |
|
63 |
// value to be displayed |
|
64 |
if (data.length && data[0].length == 2) { |
|
65 |
options.formatItem = function(row) { return row[1]; }; |
|
66 |
self.hideRealValue(node); |
|
67 |
self.setCurrentValue(node, data); |
|
68 |
} |
|
69 |
jQuery(node).autocomplete(data, options); |
|
70 |
}); |
|
71 |
}, |
|
72 |
||
73 |
hideRealValue: function(node) { |
|
74 |
var hidden = INPUT({'type': "hidden", 'name': node.name, 'value': node.value}); |
|
75 |
node.parentNode.appendChild(hidden); |
|
76 |
// remove 'name' attribute from visible input so that it is not submitted |
|
77 |
// and set correct value in the corresponding hidden field |
|
78 |
jQuery(node).removeAttr('name').bind('result', function(_, row, _) { |
|
79 |
hidden.value = row[0]; |
|
80 |
}); |
|
81 |
}, |
|
82 |
||
83 |
setCurrentValue: function(node, data) { |
|
84 |
// called when the data is loaded to reset the correct displayed |
|
85 |
// value in the visible input field (typically replacing an eid |
|
86 |
// by a displayable value) |
|
87 |
var curvalue = node.value; |
|
88 |
if (!node.value) { |
|
89 |
return; |
|
90 |
} |
|
91 |
for (var i=0,length=data.length; i<length; i++) { |
|
92 |
var row = data[i]; |
|
93 |
if (row[0] == curvalue) { |
|
94 |
node.value = row[1]; |
|
95 |
return; |
|
96 |
} |
|
97 |
} |
|
98 |
} |
|
99 |
}); |
|
100 |
||
101 |
Widgets.StaticFileSuggestField = defclass('StaticSuggestField', [Widgets.SuggestField], { |
|
102 |
||
103 |
__init__ : function(node) { |
|
104 |
Widgets.SuggestField.__init__(this, node, {method: 'get'}); |
|
105 |
} |
|
106 |
||
107 |
}); |
|
108 |
||
109 |
Widgets.RestrictedSuggestField = defclass('RestrictedSuggestField', [Widgets.SuggestField], { |
|
110 |
||
111 |
__init__ : function(node) { |
|
112 |
Widgets.SuggestField.__init__(this, node, {mustMatch: true}); |
|
113 |
} |
|
114 |
||
115 |
}); |
|
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
116 |
//remote version of RestrictedSuggestField |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
117 |
Widgets.LazySuggestField = defclass('LazySuggestField', [Widgets.SuggestField], { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
118 |
__init__: function(node, options) { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
119 |
var self = this; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
120 |
var multi = "no"; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
121 |
options = options || {}; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
122 |
options.max = 50; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
123 |
options.delay = 50; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
124 |
options.cacheLength=0; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
125 |
options.mustMatch = true; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
126 |
// multiple selection not supported yet (still need to formalize correctly |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
127 |
// initial values / display values) |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
128 |
var initialvalue = evalJSON(node.getAttribute('cubicweb:initialvalue') || 'null'); |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
129 |
if (!initialvalue) { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
130 |
initialvalue = node.value; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
131 |
} |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
132 |
options = jQuery.extend({dataType: 'json', |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
133 |
multiple: (multi == "yes") ? true : false, |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
134 |
parse: this.parseResult |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
135 |
}, options); |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
136 |
var dataurl = node.getAttribute('cubicweb:dataurl'); |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
137 |
// remove 'name' from original input and add the hidden one that will |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
138 |
// store the actual value |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
139 |
var hidden = INPUT({'type': "hidden", 'name': node.name, 'value': initialvalue}); |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
140 |
node.parentNode.appendChild(hidden); |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
141 |
jQuery(node).bind('result', {hinput: hidden, input:node}, self.hideRealValue) |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
142 |
.removeAttr('name').autocomplete(dataurl, options); |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
143 |
}, |
0 | 144 |
|
145 |
||
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
146 |
hideRealValue: function(evt, data, value) { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
147 |
if (!value){ |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
148 |
value=""; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
149 |
} |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
150 |
evt.data.hinput.value = value; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
151 |
}, |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
152 |
|
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
153 |
/* |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
154 |
* @param data: a list of couple (value, label) to fill the suggestion list, |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
155 |
* (returned by CW through AJAX) |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
156 |
*/ |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
157 |
parseResult: function(data) { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
158 |
var parsed = []; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
159 |
for (var i=0; i < data.length; i++) { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
160 |
var value = ''+data[i][0]; // a string is required later by jquery.autocomplete.js |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
161 |
var label = data[i][1]; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
162 |
parsed[parsed.length] = { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
163 |
data: [label], |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
164 |
value: value, |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
165 |
result: label |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
166 |
}; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
167 |
}; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
168 |
return parsed; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
169 |
} |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
170 |
|
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
171 |
}); |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
172 |
|
0 | 173 |
/* |
174 |
* suggestform displays a suggest field and associated validate / cancel buttons |
|
175 |
* constructor's argumemts are the same that BaseSuggestField widget |
|
176 |
*/ |
|
177 |
Widgets.SuggestForm = defclass("SuggestForm", null, { |
|
178 |
||
179 |
__init__ : function(inputid, initfunc, varargs, validatefunc, options) { |
|
180 |
this.validatefunc = validatefunc || noop; |
|
181 |
this.sgfield = new Widgets.BaseSuggestField(inputid, initfunc, |
|
182 |
varargs, options); |
|
183 |
this.oklabel = options.oklabel || 'ok'; |
|
184 |
this.cancellabel = options.cancellabel || 'cancel'; |
|
185 |
bindMethods(this); |
|
186 |
connect(this.sgfield, 'validate', this, this.entryValidated); |
|
187 |
}, |
|
188 |
||
189 |
show : function(parentnode) { |
|
190 |
var sgnode = this.sgfield.builddom(); |
|
191 |
var buttons = DIV({'class' : "sgformbuttons"}, |
|
192 |
[A({'href' : "javascript: noop();", |
|
193 |
'onclick' : this.onValidateClicked}, this.oklabel), |
|
194 |
' / ', |
|
195 |
A({'href' : "javascript: noop();", |
|
196 |
'onclick' : this.destroy}, escapeHTML(this.cancellabel))]); |
|
197 |
var formnode = DIV({'class' : "sgform"}, [sgnode, buttons]); |
|
198 |
appendChildNodes(parentnode, formnode); |
|
199 |
this.sgfield.textinput.focus(); |
|
200 |
this.formnode = formnode; |
|
201 |
return formnode; |
|
202 |
}, |
|
203 |
||
204 |
destroy : function() { |
|
205 |
signal(this, 'destroy'); |
|
206 |
this.sgfield.destroy(); |
|
207 |
removeElement(this.formnode); |
|
208 |
}, |
|
209 |
||
210 |
onValidateClicked : function() { |
|
211 |
this.validatefunc(this, this.sgfield.taglist()); |
|
212 |
}, |
|
213 |
/* just an indirection to pass the form instead of the sgfield as first parameter */ |
|
214 |
entryValidated : function(sgfield, taglist) { |
|
215 |
this.validatefunc(this, taglist); |
|
216 |
} |
|
217 |
}); |
|
218 |
||
219 |
||
220 |
/* called when the use clicks on a tree node |
|
221 |
* - if the node has a `cubicweb:loadurl` attribute, replace the content of the node |
|
222 |
* by the url's content. |
|
223 |
* - else, there's nothing to do, let the jquery plugin handle it. |
|
224 |
*/ |
|
225 |
function toggleTree(event) { |
|
226 |
var linode = jQuery(this); |
|
227 |
var url = linode.attr('cubicweb:loadurl'); |
|
228 |
if (url) { |
|
4738
6cca4f602486
fix open/close/open subnode bug #730709
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3079
diff
changeset
|
229 |
linode.find('ul.placeholder').remove(); |
0 | 230 |
linode.loadxhtml(url, {callback: function(domnode) { |
231 |
linode.removeAttr('cubicweb:loadurl'); |
|
232 |
jQuery(domnode).treeview({toggle: toggleTree, |
|
233 |
prerendered: true}); |
|
234 |
return null; |
|
235 |
}}, 'post', 'append'); |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
||
240 |
/* widget based on SIMILE's timeline widget |
|
241 |
* http://code.google.com/p/simile-widgets/ |
|
242 |
* |
|
243 |
* Beware not to mess with SIMILE's Timeline JS namepsace ! |
|
244 |
*/ |
|
245 |
||
246 |
Widgets.TimelineWidget = defclass("TimelineWidget", null, { |
|
247 |
__init__: function (wdgnode) { |
|
248 |
var tldiv = DIV({id: "tl", style: 'height: 200px; border: 1px solid #ccc;'}); |
|
249 |
wdgnode.appendChild(tldiv); |
|
250 |
var tlunit = wdgnode.getAttribute('cubicweb:tlunit') || 'YEAR'; |
|
251 |
var eventSource = new Timeline.DefaultEventSource(); |
|
252 |
var bandData = { |
|
253 |
eventPainter: Timeline.CubicWebEventPainter, |
|
254 |
eventSource: eventSource, |
|
255 |
width: "100%", |
|
256 |
intervalUnit: Timeline.DateTime[tlunit.toUpperCase()], |
|
257 |
intervalPixels: 100 |
|
258 |
}; |
|
259 |
var bandInfos = [ Timeline.createBandInfo(bandData) ]; |
|
260 |
var tl = Timeline.create(tldiv, bandInfos); |
|
261 |
var loadurl = wdgnode.getAttribute('cubicweb:loadurl'); |
|
262 |
Timeline.loadJSON(loadurl, function(json, url) { |
|
263 |
eventSource.loadJSON(json, url); }); |
|
264 |
||
265 |
} |
|
266 |
}); |
|
267 |
||
268 |
Widgets.TemplateTextField = defclass("TemplateTextField", null, { |
|
269 |
||
270 |
__init__ : function(wdgnode) { |
|
271 |
this.variables = getNodeAttribute(wdgnode, 'cubicweb:variables').split(','); |
|
1467
972517be96dc
sendmail form should now work as before
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1466
diff
changeset
|
272 |
this.options = {'name' : wdgnode.getAttribute('cubicweb:inputid'), |
0 | 273 |
'rows' : wdgnode.getAttribute('cubicweb:rows') || 40, |
274 |
'cols' : wdgnode.getAttribute('cubicweb:cols') || 80 |
|
275 |
}; |
|
276 |
// this.variableRegexp = /%\((\w+)\)s/; |
|
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
277 |
this.errorField = DIV({'class' : "errorMessage"}); |
0 | 278 |
this.textField = TEXTAREA(this.options); |
1327
ed2dac034fee
somewhat update to jquery, not yet finished though
sylvain.thenault@logilab.fr
parents:
923
diff
changeset
|
279 |
jQuery(this.textField).bind('keyup', {'self': this}, this.highlightInvalidVariables); |
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
280 |
jQuery('#substitutions').prepend(this.errorField); |
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
281 |
jQuery('#substitutions .errorMessage').hide(); |
1327
ed2dac034fee
somewhat update to jquery, not yet finished though
sylvain.thenault@logilab.fr
parents:
923
diff
changeset
|
282 |
wdgnode.appendChild(this.textField); |
0 | 283 |
}, |
284 |
||
285 |
/* signal callbacks */ |
|
286 |
||
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
287 |
highlightInvalidVariables : function(event) { |
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
288 |
var self = event.data.self; |
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
289 |
var text = self.textField.value; |
0 | 290 |
var unknownVariables = []; |
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
291 |
var it = 0; |
0 | 292 |
var group = null; |
293 |
var variableRegexp = /%\((\w+)\)s/g; |
|
294 |
// emulates rgx.findAll() |
|
295 |
while ( group=variableRegexp.exec(text) ) { |
|
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
296 |
if ( !self.variables.contains(group[1]) ) { |
0 | 297 |
unknownVariables.push(group[1]); |
298 |
} |
|
299 |
it++; |
|
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
300 |
if (it > 5) { |
0 | 301 |
break; |
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
302 |
} |
0 | 303 |
} |
304 |
var errText = ''; |
|
305 |
if (unknownVariables.length) { |
|
306 |
errText = "Detected invalid variables : " + ", ".join(unknownVariables); |
|
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
307 |
jQuery('#substitutions .errorMessage').show(); |
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
308 |
} else { |
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
309 |
jQuery('#substitutions .errorMessage').hide(); |
0 | 310 |
} |
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
311 |
self.errorField.innerHTML = errText; |
0 | 312 |
} |
313 |
||
314 |
}); |
|
315 |
||
316 |
/* |
|
317 |
* ComboBox with a textinput : allows to add a new value |
|
318 |
*/ |
|
319 |
||
320 |
Widgets.AddComboBox = defclass('AddComboBox', null, { |
|
321 |
__init__ : function(wdgnode) { |
|
322 |
jQuery("#add_newopt").click(function() { |
|
323 |
var new_val = jQuery("#newopt").val(); |
|
324 |
if (!new_val){ |
|
325 |
return false; |
|
326 |
} |
|
327 |
name = wdgnode.getAttribute('name').split(':'); |
|
328 |
this.rel = name[0]; |
|
329 |
this.eid_to = name[1]; |
|
330 |
this.etype_to = wdgnode.getAttribute('cubicweb:etype_to'); |
|
331 |
this.etype_from = wdgnode.getAttribute('cubicweb:etype_from'); |
|
1419 | 332 |
var d = asyncRemoteExec('add_and_link_new_entity', this.etype_to, this.rel, this.eid_to, this.etype_from, 'new_val'); |
0 | 333 |
d.addCallback(function (eid) { |
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
334 |
jQuery(wdgnode).find("option[selected]").removeAttr("selected"); |
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
335 |
var new_option = OPTION({'value':eid, 'selected':'selected'}, value=new_val); |
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
336 |
wdgnode.appendChild(new_option); |
0 | 337 |
}); |
338 |
d.addErrback(function (xxx) { |
|
1466
07a2d0c387ca
[widgets] fix rendering of the sendmail widget, still to functional though
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1419
diff
changeset
|
339 |
log('xxx =', xxx); |
0 | 340 |
}); |
341 |
}); |
|
342 |
} |
|
343 |
}); |
|
344 |
||
345 |
||
346 |
CubicWeb.provide('widgets.js'); |