author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Mon, 15 Nov 2010 19:38:31 +0100 | |
branch | stable |
changeset 6702 | dfc19a6fb8aa |
parent 6450 | c23639f26ec6 |
child 6739 | 08cfa7019b27 |
permissions | -rw-r--r-- |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
1 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
2 |
* Functions dedicated to widgets. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
3 |
* |
0 | 4 |
* :organization: Logilab |
5767
1d811df051c2
[packaging] MANIFEST.in cleanups, update js/css copyright, remove no more used files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4901
diff
changeset
|
5 |
* :copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 6 |
* :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7 |
* |
|
8 |
* |
|
9 |
*/ |
|
10 |
||
11 |
// widget namespace |
|
12 |
Widgets = {}; |
|
13 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
14 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
15 |
* .. function:: buildWidget(wdgnode) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
16 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
17 |
* this function takes a DOM node defining a widget and |
0 | 18 |
* instantiates / builds the appropriate widget class |
19 |
*/ |
|
20 |
function buildWidget(wdgnode) { |
|
21 |
var wdgclass = Widgets[wdgnode.getAttribute('cubicweb:wdgtype')]; |
|
22 |
if (wdgclass) { |
|
6372
4c3e2a92e340
timeline view minor enhancements
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5909
diff
changeset
|
23 |
return new wdgclass(wdgnode); |
0 | 24 |
} |
6372
4c3e2a92e340
timeline view minor enhancements
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5909
diff
changeset
|
25 |
return null; |
0 | 26 |
} |
27 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
28 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
29 |
* .. function:: buildWidgets(root) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
30 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
31 |
* This function is called on load and is in charge to build |
0 | 32 |
* JS widgets according to DOM nodes found in the page |
33 |
*/ |
|
34 |
function buildWidgets(root) { |
|
35 |
root = root || document; |
|
36 |
jQuery(root).find('.widget').each(function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
37 |
if (this.getAttribute('cubicweb:loadtype') == 'auto') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
38 |
buildWidget(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
39 |
} |
0 | 40 |
}); |
41 |
} |
|
42 |
||
43 |
// we need to differenciate cases where initFacetBoxEvents is called |
|
44 |
// with one argument or without any argument. If we use `initFacetBoxEvents` |
|
45 |
// as the direct callback on the jQuery.ready event, jQuery will pass some argument |
|
46 |
// of his, so we use this small anonymous function instead. |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
47 |
jQuery(document).ready(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
48 |
buildWidgets(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
49 |
}); |
0 | 50 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
51 |
function postJSON(url, data, callback) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
52 |
return jQuery.post(url, data, callback, 'json'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
53 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
54 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
55 |
function getJSON(url, data, callback) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
56 |
return jQuery.get(url, data, callback, 'json'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
57 |
} |
0 | 58 |
|
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
59 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
60 |
(function ($) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
61 |
var defaultSettings = { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
62 |
initialvalue: '', |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
63 |
multiple: false, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
64 |
mustMatch: false, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
65 |
delay: 50, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
66 |
limit: 50 |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
67 |
}; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
68 |
function split(val) { return val.split( /\s*,\s*/ ); } |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
69 |
function extractLast(term) { return split(term).pop(); } |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
70 |
function allButLast(val) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
71 |
var terms = split(val); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
72 |
terms.pop(); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
73 |
return terms; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
74 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
75 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
76 |
var methods = { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
77 |
__init__: function(suggestions, options) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
78 |
return this.each(function() { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
79 |
// here, `this` refers to the DOM element (e.g. input) being wrapped |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
80 |
// by cwautomplete plugin |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
81 |
var instanceData = $(this).data('cwautocomplete'); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
82 |
if (instanceData) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
83 |
// already initialized |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
84 |
return; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
85 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
86 |
var settings = $.extend({}, defaultSettings, options); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
87 |
instanceData = { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
88 |
initialvalue: settings.initialvalue, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
89 |
userInput: this, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
90 |
hiddenInput: null |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
91 |
}; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
92 |
var hiHandlers = methods.hiddenInputHandlers; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
93 |
$(this).data('cwautocomplete', instanceData); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
94 |
$.ui.autocomplete.prototype._search = methods.search; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
95 |
if (settings.multiple) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
96 |
$.ui.autocomplete.filter = methods.multiple.makeFilter(this); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
97 |
$(this).bind({ |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
98 |
autocompleteselect: methods.multiple.select, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
99 |
autocompletefocus: methods.multiple.focus, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
100 |
keydown: methods.multiple.keydown |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
101 |
}); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
102 |
} |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
103 |
// XXX katia we dont need it if minLength == 0, but by setting minLength = 0 |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
104 |
// we probably break the backward compatibility |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
105 |
$(this).bind('blur', methods.blur); |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
106 |
if ($.isArray(suggestions)) { // precomputed list of suggestions |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
107 |
settings.source = hiHandlers.checkSuggestionsDataFormat(instanceData, suggestions); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
108 |
} else { // url to call each time something is typed |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
109 |
settings.source = function(request, response) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
110 |
var d = loadRemote(suggestions, {q: request.term, limit: settings.limit}, 'POST'); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
111 |
d.addCallback(function (suggestions) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
112 |
suggestions = hiHandlers.checkSuggestionsDataFormat(instanceData, suggestions); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
113 |
response(suggestions); |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
114 |
if((suggestions.length) == 0){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
115 |
methods.resetValues(instanceData); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
116 |
} |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
117 |
}); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
118 |
}; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
119 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
120 |
$(this).autocomplete(settings); |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
121 |
if (settings.mustMatch) { |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
122 |
$(this).keypress(methods.ensureExactMatch); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
123 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
124 |
}); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
125 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
126 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
127 |
multiple: { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
128 |
focus: function() { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
129 |
// prevent value inserted on focus |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
130 |
return false; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
131 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
132 |
select: function(event, ui) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
133 |
var terms = allButLast(this.value); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
134 |
// add the selected item |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
135 |
terms.push(ui.item.value); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
136 |
// add placeholder to get the comma-and-space at the end |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
137 |
terms.push(""); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
138 |
this.value = terms.join( ", " ); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
139 |
return false; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
140 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
141 |
keydown: function(evt) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
142 |
if ($(this).data('autocomplete').menu.active && evt.keyCode == $.ui.keyCode.TAB) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
143 |
evt.preventDefault(); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
144 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
145 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
146 |
makeFilter: function(userInput) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
147 |
return function(array, term) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
148 |
// remove already entered terms from suggestion list |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
149 |
array = cw.utils.difference(array, allButLast(userInput.value)); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
150 |
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" ); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
151 |
return $.grep( array, function(value) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
152 |
return matcher.test( value.label || value.value || value ); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
153 |
}); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
154 |
}; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
155 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
156 |
}, |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
157 |
blur: function(evt){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
158 |
var instanceData = $(this).data('cwautocomplete'); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
159 |
if($(instanceData.userInput).val().strip().length==0){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
160 |
methods.resetValues(instanceData); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
161 |
} |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
162 |
}, |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
163 |
search: function(value) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
164 |
this.element.addClass("ui-autocomplete-loading"); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
165 |
if (this.options.multiple) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
166 |
value = extractLast(value); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
167 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
168 |
this.source({term: value}, this.response); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
169 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
170 |
ensureExactMatch: function(evt) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
171 |
var instanceData = $(this).data('cwautocomplete'); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
172 |
if (evt.keyCode == $.ui.keyCode.ENTER || evt.keyCode == $.ui.keyCode.TAB) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
173 |
var validChoices = $.map($('ul.ui-autocomplete li'), |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
174 |
function(li) {return $(li).text();}); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
175 |
if ($.inArray($(instanceData.userInput).val(), validChoices) == -1) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
176 |
$(instanceData.userInput).val(''); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
177 |
$(instanceData.hiddenInput).val(instanceData.initialvalue || ''); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
178 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
179 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
180 |
}, |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
181 |
resetValues: function(instanceData){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
182 |
$(instanceData.userInput).val(''); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
183 |
$(instanceData.hiddenInput).val(''); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
184 |
}, |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
185 |
|
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
186 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
187 |
hiddenInputHandlers: { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
188 |
/** |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
189 |
* `hiddenInputHandlers` defines all methods specific to handle the |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
190 |
* hidden input created along the standard text input. |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
191 |
* An hiddenInput is necessary when displayed suggestions are |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
192 |
* different from actual values to submit. |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
193 |
* Imagine an autocompletion widget to choose among a list of CWusers. |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
194 |
* Suggestions would be the list of logins, but actual values would |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
195 |
* be the corresponding eids. |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
196 |
* To handle such cases, suggestions list should be a list of JS objects |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
197 |
* with two `label` and `value` properties. |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
198 |
**/ |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
199 |
suggestionSelected: function(evt, ui) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
200 |
var instanceData = $(this).data('cwautocomplete'); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
201 |
instanceData.hiddenInput.value = ui.item.value; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
202 |
instanceData.value = ui.item.label; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
203 |
return false; // stop propagation |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
204 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
205 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
206 |
suggestionFocusChanged: function(evt, ui) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
207 |
var instanceData = $(this).data('cwautocomplete'); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
208 |
instanceData.userInput.value = ui.item.label; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
209 |
return false; // stop propagation |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
210 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
211 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
212 |
needsHiddenInput: function(suggestions) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
213 |
return suggestions[0].label !== undefined; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
214 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
215 |
initializeHiddenInput: function(instanceData) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
216 |
var userInput = instanceData.userInput; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
217 |
var hiddenInput = INPUT({ |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
218 |
type: "hidden", |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
219 |
name: userInput.name, |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
220 |
// XXX katia : this must be handeled in .SuggestField widget, but |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
221 |
// it seems not to be used anymore |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
222 |
value: $(userInput).attr('cubicweb:initialvalue') || userInput.value |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
223 |
}); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
224 |
$(userInput).removeAttr('name').after(hiddenInput); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
225 |
instanceData.hiddenInput = hiddenInput; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
226 |
$(userInput).bind({ |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
227 |
autocompleteselect: methods.hiddenInputHandlers.suggestionSelected, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
228 |
autocompletefocus: methods.hiddenInputHandlers.suggestionFocusChanged |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
229 |
}); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
230 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
231 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
232 |
/* |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
233 |
* internal convenience function: old jquery plugin accepted to be fed |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
234 |
* with a list of couples (value, label). The new (jquery-ui) autocomplete |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
235 |
* plugin expects a list of objects with "value" and "label" properties. |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
236 |
* |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
237 |
* This function converts the old format to the new one. |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
238 |
*/ |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
239 |
checkSuggestionsDataFormat: function(instanceData, suggestions) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
240 |
// check for old (value, label) format |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
241 |
if ($.isArray(suggestions) && suggestions.length && |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
242 |
$.isArray(suggestions[0])){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
243 |
if (suggestions[0].length == 2) { |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
244 |
cw.log('[3.10] autocomplete init func should return {label,value} dicts instead of lists'); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
245 |
suggestions = $.map(suggestions, function(sugg) { |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
246 |
return {value: sugg[0], label: sugg[1]}; |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
247 |
}); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
248 |
} else { |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
249 |
if(suggestions[0].length == 1){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
250 |
suggestions = $.map(suggestions, function(sugg) { |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
251 |
return {value: sugg[0], label: sugg[0]}; |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
252 |
}); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
253 |
} |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
254 |
} |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
255 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
256 |
var hiHandlers = methods.hiddenInputHandlers; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
257 |
if (suggestions.length && hiHandlers.needsHiddenInput(suggestions) |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
258 |
&& !instanceData.hiddenInput) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
259 |
hiHandlers.initializeHiddenInput(instanceData); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
260 |
hiHandlers.fixUserInputInitialValue(instanceData, suggestions); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
261 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
262 |
// otherwise, assume data shape is correct |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
263 |
return suggestions; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
264 |
}, |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
265 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
266 |
fixUserInputInitialValue: function(instanceData, suggestions) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
267 |
// called when the data is loaded to reset the correct displayed |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
268 |
// value in the visible input field (typically replacing an eid |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
269 |
// by a displayable value) |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
270 |
var curvalue = instanceData.userInput.value; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
271 |
if (!curvalue) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
272 |
return; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
273 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
274 |
for (var i=0, length=suggestions.length; i < length; i++) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
275 |
var sugg = suggestions[i]; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
276 |
if (sugg.value == curvalue) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
277 |
instanceData.userInput.value = sugg.label; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
278 |
return; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
279 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
280 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
281 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
282 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
283 |
}; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
284 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
285 |
$.fn.cwautocomplete = function(data, options) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
286 |
return methods.__init__.apply(this, [data, options]); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
287 |
}; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
288 |
})(jQuery); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
289 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
290 |
|
0 | 291 |
Widgets.SuggestField = defclass('SuggestField', null, { |
292 |
__init__: function(node, options) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
293 |
options = options || {}; |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
294 |
var multi = node.getAttribute('cubicweb:multi'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
295 |
options.multiple = (multi == "yes") ? true: false; |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
296 |
var d = loadRemote(node.getAttribute('cubicweb:dataurl')); |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
297 |
d.addCallback(function(data) { |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
298 |
$(node).cwautocomplete(data, options); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
299 |
}); |
0 | 300 |
} |
301 |
}); |
|
302 |
||
303 |
Widgets.StaticFileSuggestField = defclass('StaticSuggestField', [Widgets.SuggestField], { |
|
304 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
305 |
__init__: function(node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
306 |
Widgets.SuggestField.__init__(this, node, { |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
307 |
method: 'get' // XXX |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
308 |
}); |
0 | 309 |
} |
310 |
||
311 |
}); |
|
312 |
||
313 |
Widgets.RestrictedSuggestField = defclass('RestrictedSuggestField', [Widgets.SuggestField], { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
314 |
__init__: function(node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
315 |
Widgets.SuggestField.__init__(this, node, { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
316 |
mustMatch: true |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
317 |
}); |
0 | 318 |
} |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
319 |
}); |
0 | 320 |
|
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
321 |
//remote version of RestrictedSuggestField |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
322 |
Widgets.LazySuggestField = defclass('LazySuggestField', [Widgets.SuggestField], { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
323 |
__init__: function(node, options) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
324 |
var self = this; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
325 |
options = options || {}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
326 |
options.delay = 50; |
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
327 |
// 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
|
328 |
// initial values / display values) |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
329 |
var initialvalue = cw.evalJSON(node.getAttribute('cubicweb:initialvalue') || 'null'); |
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
330 |
if (!initialvalue) { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
331 |
initialvalue = node.value; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
332 |
} |
6448
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
333 |
options.initialvalue = initialvalue; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
334 |
Widgets.SuggestField.__init__(this, node, options); |
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
335 |
} |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
336 |
}); |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
337 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
338 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
339 |
* .. class:: Widgets.SuggestForm |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
340 |
* |
0 | 341 |
* suggestform displays a suggest field and associated validate / cancel buttons |
342 |
* constructor's argumemts are the same that BaseSuggestField widget |
|
343 |
*/ |
|
344 |
Widgets.SuggestForm = defclass("SuggestForm", null, { |
|
345 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
346 |
__init__: function(inputid, initfunc, varargs, validatefunc, options) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
347 |
this.validatefunc = validatefunc || noop; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
348 |
this.sgfield = new Widgets.BaseSuggestField(inputid, initfunc, varargs, options); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
349 |
this.oklabel = options.oklabel || 'ok'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
350 |
this.cancellabel = options.cancellabel || 'cancel'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
351 |
bindMethods(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
352 |
connect(this.sgfield, 'validate', this, this.entryValidated); |
0 | 353 |
}, |
354 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
355 |
show: function(parentnode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
356 |
var sgnode = this.sgfield.builddom(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
357 |
var buttons = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
358 |
'class': "sgformbuttons" |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
359 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
360 |
[A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
361 |
'href': "javascript: noop();", |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
362 |
'onclick': this.onValidateClicked |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
363 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
364 |
this.oklabel), ' / ', A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
365 |
'href': "javascript: noop();", |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
366 |
'onclick': this.destroy |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
367 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
368 |
escapeHTML(this.cancellabel))]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
369 |
var formnode = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
370 |
'class': "sgform" |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
371 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
372 |
[sgnode, buttons]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
373 |
appendChildNodes(parentnode, formnode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
374 |
this.sgfield.textinput.focus(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
375 |
this.formnode = formnode; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
376 |
return formnode; |
0 | 377 |
}, |
378 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
379 |
destroy: function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
380 |
signal(this, 'destroy'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
381 |
this.sgfield.destroy(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
382 |
removeElement(this.formnode); |
0 | 383 |
}, |
384 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
385 |
onValidateClicked: function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
386 |
this.validatefunc(this, this.sgfield.taglist()); |
0 | 387 |
}, |
388 |
/* just an indirection to pass the form instead of the sgfield as first parameter */ |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
389 |
entryValidated: function(sgfield, taglist) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
390 |
this.validatefunc(this, taglist); |
0 | 391 |
} |
392 |
}); |
|
393 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
394 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
395 |
* .. function:: toggleTree(event) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
396 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
397 |
* called when the use clicks on a tree node |
0 | 398 |
* - if the node has a `cubicweb:loadurl` attribute, replace the content of the node |
399 |
* by the url's content. |
|
400 |
* - else, there's nothing to do, let the jquery plugin handle it. |
|
401 |
*/ |
|
402 |
function toggleTree(event) { |
|
403 |
var linode = jQuery(this); |
|
404 |
var url = linode.attr('cubicweb:loadurl'); |
|
405 |
if (url) { |
|
4738
6cca4f602486
fix open/close/open subnode bug #730709
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3079
diff
changeset
|
406 |
linode.find('ul.placeholder').remove(); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
407 |
linode.loadxhtml(url, { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
408 |
callback: function(domnode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
409 |
linode.removeAttr('cubicweb:loadurl'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
410 |
jQuery(domnode).treeview({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
411 |
toggle: toggleTree, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
412 |
prerendered: true |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
413 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
414 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
415 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
416 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
417 |
'post', 'append'); |
0 | 418 |
} |
419 |
} |
|
420 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
421 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
422 |
* .. class:: Widgets.TimelineWidget |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
423 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
424 |
* widget based on SIMILE's timeline widget |
0 | 425 |
* http://code.google.com/p/simile-widgets/ |
426 |
* |
|
427 |
* Beware not to mess with SIMILE's Timeline JS namepsace ! |
|
428 |
*/ |
|
429 |
||
430 |
Widgets.TimelineWidget = defclass("TimelineWidget", null, { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
431 |
__init__: function(wdgnode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
432 |
var tldiv = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
433 |
id: "tl", |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
434 |
style: 'height: 200px; border: 1px solid #ccc;' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
435 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
436 |
wdgnode.appendChild(tldiv); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
437 |
var tlunit = wdgnode.getAttribute('cubicweb:tlunit') || 'YEAR'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
438 |
var eventSource = new Timeline.DefaultEventSource(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
439 |
var bandData = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
440 |
eventPainter: Timeline.CubicWebEventPainter, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
441 |
eventSource: eventSource, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
442 |
width: "100%", |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
443 |
intervalUnit: Timeline.DateTime[tlunit.toUpperCase()], |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
444 |
intervalPixels: 100 |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
445 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
446 |
var bandInfos = [Timeline.createBandInfo(bandData)]; |
6372
4c3e2a92e340
timeline view minor enhancements
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5909
diff
changeset
|
447 |
this.tl = Timeline.create(tldiv, bandInfos); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
448 |
var loadurl = wdgnode.getAttribute('cubicweb:loadurl'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
449 |
Timeline.loadJSON(loadurl, function(json, url) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
450 |
eventSource.loadJSON(json, url); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
451 |
}); |
0 | 452 |
|
453 |
} |
|
454 |
}); |
|
455 |
||
456 |
Widgets.TemplateTextField = defclass("TemplateTextField", null, { |
|
457 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
458 |
__init__: function(wdgnode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
459 |
this.variables = jQuery(wdgnode).attr('cubicweb:variables').split(','); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
460 |
this.options = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
461 |
name: wdgnode.getAttribute('cubicweb:inputid'), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
462 |
rows: wdgnode.getAttribute('cubicweb:rows') || 40, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
463 |
cols: wdgnode.getAttribute('cubicweb:cols') || 80 |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
464 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
465 |
// this.variableRegexp = /%\((\w+)\)s/; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
466 |
this.errorField = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
467 |
'class': "errorMessage" |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
468 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
469 |
this.textField = TEXTAREA(this.options); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
470 |
jQuery(this.textField).bind('keyup', { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
471 |
'self': this |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
472 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
473 |
this.highlightInvalidVariables); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
474 |
jQuery('#substitutions').prepend(this.errorField); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
475 |
jQuery('#substitutions .errorMessage').hide(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
476 |
wdgnode.appendChild(this.textField); |
0 | 477 |
}, |
478 |
||
479 |
/* signal callbacks */ |
|
480 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
481 |
highlightInvalidVariables: function(event) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
482 |
var self = event.data.self; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
483 |
var text = self.textField.value; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
484 |
var unknownVariables = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
485 |
var it = 0; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
486 |
var group = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
487 |
var variableRegexp = /%\((\w+)\)s/g; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
488 |
// emulates rgx.findAll() |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
489 |
while (group = variableRegexp.exec(text)) { |
5909
9af8ac182f53
[javascript] fix some javascript errors and remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5774
diff
changeset
|
490 |
if (!$.inArray(group[1], self.variables)) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
491 |
unknownVariables.push(group[1]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
492 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
493 |
it++; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
494 |
if (it > 5) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
495 |
break; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
496 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
497 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
498 |
var errText = ''; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
499 |
if (unknownVariables.length) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
500 |
errText = "Detected invalid variables : " + unknownVariables.join(', '); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
501 |
jQuery('#substitutions .errorMessage').show(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
502 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
503 |
jQuery('#substitutions .errorMessage').hide(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
504 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
505 |
self.errorField.innerHTML = errText; |
0 | 506 |
} |
507 |
||
508 |
}); |
|
509 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
510 |
cw.widgets = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
511 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
512 |
* .. function:: insertText(text, areaId) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
513 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
514 |
* inspects textarea with id `areaId` and replaces the current selected text |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
515 |
* with `text`. Cursor is then set at the end of the inserted text. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
516 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
517 |
insertText: function (text, areaId) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
518 |
var textarea = jQuery('#' + areaId); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
519 |
if (document.selection) { // IE |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
520 |
var selLength; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
521 |
textarea.focus(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
522 |
var sel = document.selection.createRange(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
523 |
selLength = sel.text.length; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
524 |
sel.text = text; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
525 |
sel.moveStart('character', selLength - text.length); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
526 |
sel.select(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
527 |
} else if (textarea.selectionStart || textarea.selectionStart == '0') { // mozilla |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
528 |
var startPos = textarea.selectionStart; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
529 |
var endPos = textarea.selectionEnd; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
530 |
// insert text so that it replaces the [startPos, endPos] part |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
531 |
textarea.value = textarea.value.substring(0, startPos) + text + textarea.value.substring(endPos, textarea.value.length); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
532 |
// set cursor pos at the end of the inserted text |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
533 |
textarea.selectionStart = textarea.selectionEnd = startPos + text.length; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
534 |
textarea.focus(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
535 |
} else { // safety belt for other browsers |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
536 |
textarea.value += text; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
537 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
538 |
} |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
539 |
}; |