author | Rémi Cardona <remi.cardona@logilab.fr> |
Fri, 18 Sep 2015 11:58:29 +0200 | |
changeset 10707 | 3f4f190f8e35 |
parent 10465 | 5b18e2e4dd71 |
child 11048 | 96d57cb8b644 |
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 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
43 |
jQuery(document).ready(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
44 |
buildWidgets(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
45 |
}); |
0 | 46 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
47 |
function postJSON(url, data, callback) { |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7943
diff
changeset
|
48 |
return jQuery.post(url, data, callback, AJAX_BASE_URL); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
49 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
50 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
51 |
function getJSON(url, data, callback) { |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7943
diff
changeset
|
52 |
return jQuery.get(url, data, callback, AJAX_BASE_URL); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
53 |
} |
0 | 54 |
|
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
|
55 |
|
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
|
56 |
(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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
}; |
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 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
} |
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 |
|
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 |
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
|
73 |
__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
|
74 |
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
|
75 |
// 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
|
76 |
// 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
|
77 |
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
|
78 |
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
|
79 |
// 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
|
80 |
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
|
81 |
} |
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 |
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
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
}; |
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 |
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
|
89 |
$(this).data('cwautocomplete', instanceData); |
6739
08cfa7019b27
[js] fix initial value for autocomplete
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6450
diff
changeset
|
90 |
// in case of an existing value, the hidden input must be initialized even if |
08cfa7019b27
[js] fix initial value for autocomplete
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6450
diff
changeset
|
91 |
// the value is not changed |
08cfa7019b27
[js] fix initial value for autocomplete
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6450
diff
changeset
|
92 |
if (($(instanceData.userInput).attr('cubicweb:initialvalue') !== undefined) && !instanceData.hiddenInput){ |
08cfa7019b27
[js] fix initial value for autocomplete
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6450
diff
changeset
|
93 |
hiHandlers.initializeHiddenInput(instanceData); |
08cfa7019b27
[js] fix initial value for autocomplete
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6450
diff
changeset
|
94 |
} |
9388
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
95 |
$.ui.autocomplete.prototype._value = methods._value; |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
96 |
$.data(this, 'settings', settings); |
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
|
97 |
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
|
98 |
$.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
|
99 |
$(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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
}); |
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
|
104 |
} |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
105 |
// 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
|
106 |
// 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
|
107 |
$(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
|
108 |
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
|
109 |
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
|
110 |
} 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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
response(suggestions); |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
116 |
if((suggestions.length) == 0){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
117 |
methods.resetValues(instanceData); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
118 |
} |
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
|
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 |
}; |
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
|
121 |
} |
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).autocomplete(settings); |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
123 |
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
|
124 |
$(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
|
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 |
}, |
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 |
|
9388
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
129 |
_value: function() { |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
130 |
/* We extend the widget with the ability to lookup and |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
131 |
handle several terms at once ('multiple' option). E.g.: |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
132 |
toto, titi, tu.... The autocompletion must be |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
133 |
performed only on the last of such a list of terms. |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
134 |
*/ |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
135 |
var settings = $(this.element).data('settings'); |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
136 |
var value = this.valueMethod.apply( this.element, arguments ); |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
137 |
if (settings.multiple & arguments.length === 0) { |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
138 |
return extractLast(value); |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
139 |
} |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
140 |
return value |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
141 |
}, |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
142 |
|
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
|
143 |
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
|
144 |
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
|
145 |
// 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
|
146 |
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
|
147 |
}, |
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 |
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
|
149 |
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
|
150 |
// 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
|
151 |
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
|
152 |
// 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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
}, |
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
|
157 |
keydown: function(evt) { |
9388
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
158 |
if (evt.keyCode == $.ui.keyCode.TAB) { |
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
|
159 |
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
|
160 |
} |
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
|
161 |
}, |
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
|
162 |
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
|
163 |
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
|
164 |
// 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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
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
|
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 |
}; |
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 |
} |
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 |
}, |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
173 |
blur: function(evt){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
174 |
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
|
175 |
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
|
176 |
methods.resetValues(instanceData); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
177 |
} |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
178 |
}, |
9388
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
179 |
|
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
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
$(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
|
187 |
$(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
|
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 |
} |
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 |
}, |
9388
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
191 |
|
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
192 |
resetValues: function(instanceData){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
193 |
$(instanceData.userInput).val(''); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
194 |
$(instanceData.hiddenInput).val(''); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
195 |
}, |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
196 |
|
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
|
197 |
|
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 |
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
|
199 |
/** |
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 |
* `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
|
201 |
* 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
|
202 |
* 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
|
203 |
* 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
|
204 |
* 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
|
205 |
* 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
|
206 |
* 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
|
207 |
* 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
|
208 |
* 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
|
209 |
**/ |
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 |
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
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
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
|
215 |
}, |
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 |
|
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 |
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
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
}, |
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
|
222 |
|
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 |
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
|
224 |
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
|
225 |
}, |
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 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
name: userInput.name, |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
231 |
// 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
|
232 |
// 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
|
233 |
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
|
234 |
}); |
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 |
$(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
|
236 |
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
|
237 |
$(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
|
238 |
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
|
239 |
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
|
240 |
}); |
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 |
}, |
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
|
242 |
|
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
|
243 |
/* |
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
|
244 |
* 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
|
245 |
* 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
|
246 |
* 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
|
247 |
* |
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
|
248 |
* 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
|
249 |
*/ |
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
|
250 |
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
|
251 |
// 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
|
252 |
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
|
253 |
$.isArray(suggestions[0])){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
}); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
259 |
} else { |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
}); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
264 |
} |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
265 |
} |
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
|
266 |
} |
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 |
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
|
268 |
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
|
269 |
&& !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
|
270 |
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
|
271 |
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
|
272 |
} |
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 |
// 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
|
274 |
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
|
275 |
}, |
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 |
|
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 |
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
|
278 |
// 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
|
279 |
// 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
|
280 |
// 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
|
281 |
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
|
282 |
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
|
283 |
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
|
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 |
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
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
} |
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
|
291 |
} |
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
|
292 |
} |
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
|
293 |
} |
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 |
}; |
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
|
295 |
|
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 |
$.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
|
297 |
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
|
298 |
}; |
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
|
299 |
})(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
|
300 |
|
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
|
301 |
|
0 | 302 |
Widgets.SuggestField = defclass('SuggestField', null, { |
303 |
__init__: function(node, options) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
304 |
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
|
305 |
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
|
306 |
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
|
307 |
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
|
308 |
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
|
309 |
$(node).cwautocomplete(data, options); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
310 |
}); |
0 | 311 |
} |
312 |
}); |
|
313 |
||
314 |
Widgets.StaticFileSuggestField = defclass('StaticSuggestField', [Widgets.SuggestField], { |
|
315 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
316 |
__init__: function(node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
317 |
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
|
318 |
method: 'get' // XXX |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
319 |
}); |
0 | 320 |
} |
321 |
||
322 |
}); |
|
323 |
||
324 |
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
|
325 |
__init__: function(node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
326 |
Widgets.SuggestField.__init__(this, node, { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
327 |
mustMatch: true |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
328 |
}); |
0 | 329 |
} |
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
|
330 |
}); |
0 | 331 |
|
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
332 |
//remote version of RestrictedSuggestField |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
333 |
Widgets.LazySuggestField = defclass('LazySuggestField', [Widgets.SuggestField], { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
334 |
__init__: function(node, options) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
335 |
var self = this; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
336 |
options = options || {}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
337 |
options.delay = 50; |
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
338 |
// 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
|
339 |
// initial values / display values) |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
340 |
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
|
341 |
if (!initialvalue) { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
342 |
initialvalue = node.value; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
343 |
} |
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
|
344 |
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
|
345 |
Widgets.SuggestField.__init__(this, node, options); |
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
346 |
} |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
347 |
}); |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
348 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
349 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
350 |
* .. function:: toggleTree(event) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
351 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
352 |
* called when the use clicks on a tree node |
0 | 353 |
* - if the node has a `cubicweb:loadurl` attribute, replace the content of the node |
354 |
* by the url's content. |
|
355 |
* - else, there's nothing to do, let the jquery plugin handle it. |
|
356 |
*/ |
|
357 |
function toggleTree(event) { |
|
358 |
var linode = jQuery(this); |
|
359 |
var url = linode.attr('cubicweb:loadurl'); |
|
360 |
if (url) { |
|
4738
6cca4f602486
fix open/close/open subnode bug #730709
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3079
diff
changeset
|
361 |
linode.find('ul.placeholder').remove(); |
9529
39b46b0b01e4
[web/data] fix treeview regression (closes #3526466)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9388
diff
changeset
|
362 |
var d = linode.loadxhtml(url, null, 'post', 'append'); |
39b46b0b01e4
[web/data] fix treeview regression (closes #3526466)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9388
diff
changeset
|
363 |
d.addCallback(function(domnode) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
364 |
linode.removeAttr('cubicweb:loadurl'); |
9529
39b46b0b01e4
[web/data] fix treeview regression (closes #3526466)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9388
diff
changeset
|
365 |
linode.find('> ul.treeview').treeview({ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
366 |
toggle: toggleTree, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
367 |
prerendered: true |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
368 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
369 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
370 |
} |
9529
39b46b0b01e4
[web/data] fix treeview regression (closes #3526466)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9388
diff
changeset
|
371 |
); |
0 | 372 |
} |
373 |
} |
|
374 |
||
375 |
Widgets.TemplateTextField = defclass("TemplateTextField", null, { |
|
376 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
377 |
__init__: function(wdgnode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
378 |
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
|
379 |
this.options = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
380 |
name: wdgnode.getAttribute('cubicweb:inputid'), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
381 |
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
|
382 |
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
|
383 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
384 |
// this.variableRegexp = /%\((\w+)\)s/; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
385 |
this.errorField = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
386 |
'class': "errorMessage" |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
387 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
388 |
this.textField = TEXTAREA(this.options); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
389 |
jQuery(this.textField).bind('keyup', { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
390 |
'self': this |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
391 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
392 |
this.highlightInvalidVariables); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
393 |
jQuery('#substitutions').prepend(this.errorField); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
394 |
jQuery('#substitutions .errorMessage').hide(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
395 |
wdgnode.appendChild(this.textField); |
0 | 396 |
}, |
397 |
||
398 |
/* signal callbacks */ |
|
399 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
400 |
highlightInvalidVariables: function(event) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
401 |
var self = event.data.self; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
402 |
var text = self.textField.value; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
403 |
var unknownVariables = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
404 |
var it = 0; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
405 |
var group = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
406 |
var variableRegexp = /%\((\w+)\)s/g; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
407 |
// emulates rgx.findAll() |
7258
2e7f0d6fa2d6
[js] fix inArray usage in reorderTabIndex() : inArray returns -1 if element is not found, not 'false'
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6890
diff
changeset
|
408 |
while ( (group = variableRegexp.exec(text)) ) { |
2e7f0d6fa2d6
[js] fix inArray usage in reorderTabIndex() : inArray returns -1 if element is not found, not 'false'
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6890
diff
changeset
|
409 |
if ($.inArray(group[1], self.variables) == -1) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
410 |
unknownVariables.push(group[1]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
411 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
412 |
it++; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
413 |
if (it > 5) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
414 |
break; |
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 |
var errText = ''; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
418 |
if (unknownVariables.length) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
419 |
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
|
420 |
jQuery('#substitutions .errorMessage').show(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
421 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
422 |
jQuery('#substitutions .errorMessage').hide(); |
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 |
self.errorField.innerHTML = errText; |
0 | 425 |
} |
426 |
||
427 |
}); |
|
428 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
429 |
cw.widgets = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
430 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
431 |
* .. function:: insertText(text, areaId) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
432 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
433 |
* 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
|
434 |
* 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
|
435 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
436 |
insertText: function (text, areaId) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
437 |
var textarea = jQuery('#' + areaId); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
438 |
if (document.selection) { // IE |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
439 |
var selLength; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
440 |
textarea.focus(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
441 |
var sel = document.selection.createRange(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
442 |
selLength = sel.text.length; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
443 |
sel.text = text; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
444 |
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
|
445 |
sel.select(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
446 |
} 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
|
447 |
var startPos = textarea.selectionStart; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
448 |
var endPos = textarea.selectionEnd; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
449 |
// 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
|
450 |
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
|
451 |
// 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
|
452 |
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
|
453 |
textarea.focus(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
454 |
} 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
|
455 |
textarea.value += text; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
456 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
457 |
} |
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
|
458 |
}; |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
459 |
|
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
460 |
|
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
461 |
// InOutWidget This contains specific InOutnWidget javascript |
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
462 |
// IE things can not handle hide/show options on select, this cloned list solition (should propably have 2 widgets) |
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
463 |
|
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
464 |
(function ($) { |
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
465 |
|
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
466 |
var methods = { |
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
467 |
__init__: function(fromSelect, toSelect) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
468 |
// closed over state |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
469 |
var state = {'$fromNode' : $(cw.escape('#' + fromSelect)), |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
470 |
'$toNode' : $(cw.escape('#' + toSelect)), |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
471 |
'name' : this.attr('id')}; |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
472 |
|
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
473 |
function sortoptions($optionlist) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
474 |
var $sorted = $optionlist.find('option').sort(function(opt1, opt2) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
475 |
return $(opt1).text() > $(opt2).text() ? 1 : -1; |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
476 |
}); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
477 |
// this somehow translates to an inplace sort |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
478 |
$optionlist.append($sorted); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
479 |
}; |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
480 |
sortoptions(state.$fromNode); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
481 |
sortoptions(state.$toNode); |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
482 |
|
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
483 |
// will move selected options from one list to the other |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
484 |
// and call an option handler on each option |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
485 |
function moveoptions ($fromlist, $tolist, opthandler) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
486 |
$fromlist.find('option:selected').each(function(index, option) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
487 |
var $option = $(option); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
488 |
// add a new option to the target list |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
489 |
$tolist.append(OPTION({'value' : $option.val()}, |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
490 |
$option.text())); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
491 |
// process callback on the option |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
492 |
opthandler.call(null, $option); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
493 |
// remove option from the source list |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
494 |
$option.remove(); |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
495 |
}); |
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
496 |
// re-sort both lists |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
497 |
sortoptions($fromlist); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
498 |
sortoptions($tolist); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
499 |
}; |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
500 |
|
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
501 |
function addvalues () { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
502 |
moveoptions(state.$fromNode, state.$toNode, function ($option) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
503 |
// add an hidden input for the edit controller |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
504 |
var hiddenInput = INPUT({ |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
505 |
type: 'hidden', name: state.name, |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
506 |
value : $option.val() |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
507 |
}); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
508 |
state.$toNode.parent().append(hiddenInput); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
509 |
}); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
510 |
}; |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
511 |
|
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
512 |
function removevalues () { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
513 |
moveoptions(state.$toNode, state.$fromNode, function($option) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
514 |
// remove hidden inputs for the edit controller |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
515 |
var selector = 'input[name=' + cw.escape(state.name) + ']' |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
516 |
state.$toNode.parent().find(selector).each(function(index, input) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
517 |
if ($(input).val() == $option.val()) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
518 |
$(input).remove(); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
519 |
} |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
520 |
}); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
521 |
}); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
522 |
}; |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
523 |
|
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
524 |
var $this = $(this); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
525 |
$this.find('.cwinoutadd').bind( // 'add >>>' symbol |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
526 |
'click', {'state' : state}, addvalues); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
527 |
$this.find('.cwinoutremove').bind( // 'remove <<<' symbol |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
528 |
'click', {'state' : state}, removevalues); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
529 |
|
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
530 |
state.$fromNode.bind('dblclick', {'state': state}, addvalues); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
531 |
state.$toNode.bind('dblclick', {'state': state}, removevalues); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
532 |
|
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
533 |
} |
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
534 |
}; |
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
535 |
$.fn.cwinoutwidget = function(fromSelect, toSelect) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
536 |
return methods.__init__.apply(this, [fromSelect, toSelect]); |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
537 |
}; |
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
538 |
})(jQuery); |