author | Julien Cristau <julien.cristau@logilab.fr> |
Fri, 12 Feb 2016 15:21:21 +0100 | |
changeset 11111 | 606d4fea99f5 |
parent 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 |
||
11048
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
28 |
function renderJQueryDatePicker(subject, button_image, date_format, min_date, max_date){ |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
29 |
$widget = cw.jqNode(subject); |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
30 |
$widget.datepicker({buttonImage: button_image, dateFormat: date_format, |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
31 |
firstDay: 1, showOn: "button", buttonImageOnly: true, |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
32 |
minDate: min_date, maxDate: max_date}); |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
33 |
$widget.change(function(ev) { |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
34 |
maxOfId = $(this).data('max-of'); |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
35 |
if (maxOfId) { |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
36 |
cw.jqNode(maxOfId).datepicker("option", "maxDate", this.value); |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
37 |
} |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
38 |
minOfId = $(this).data('min-of'); |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
39 |
if (minOfId) { |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
40 |
cw.jqNode(minOfId).datepicker("option", "minDate", this.value); |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
41 |
} |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
42 |
}); |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
43 |
} |
96d57cb8b644
[views] improve JQueryDatePicker so that a date field can be defined as the min/max of an other one
Erica Marco <erica.marco@logilab.fr>
parents:
10465
diff
changeset
|
44 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
45 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
46 |
* .. function:: buildWidgets(root) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
47 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
48 |
* This function is called on load and is in charge to build |
0 | 49 |
* JS widgets according to DOM nodes found in the page |
50 |
*/ |
|
51 |
function buildWidgets(root) { |
|
52 |
root = root || document; |
|
53 |
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
|
54 |
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
|
55 |
buildWidget(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
56 |
} |
0 | 57 |
}); |
58 |
} |
|
59 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
60 |
jQuery(document).ready(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
61 |
buildWidgets(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
62 |
}); |
0 | 63 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
64 |
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
|
65 |
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
|
66 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
67 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
68 |
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
|
69 |
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
|
70 |
} |
0 | 71 |
|
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
|
72 |
|
8590d82e9b1b
[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 |
(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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
}; |
8590d82e9b1b
[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 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
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 |
|
8590d82e9b1b
[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 |
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
|
90 |
__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
|
91 |
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
|
92 |
// 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
|
93 |
// 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
|
94 |
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
|
95 |
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
|
96 |
// 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
|
97 |
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
|
98 |
} |
8590d82e9b1b
[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 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
}; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
105 |
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
|
106 |
$(this).data('cwautocomplete', instanceData); |
6739
08cfa7019b27
[js] fix initial value for autocomplete
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6450
diff
changeset
|
107 |
// 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
|
108 |
// the value is not changed |
08cfa7019b27
[js] fix initial value for autocomplete
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6450
diff
changeset
|
109 |
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
|
110 |
hiHandlers.initializeHiddenInput(instanceData); |
08cfa7019b27
[js] fix initial value for autocomplete
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6450
diff
changeset
|
111 |
} |
9388
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
112 |
$.ui.autocomplete.prototype._value = methods._value; |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
113 |
$.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
|
114 |
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
|
115 |
$.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
|
116 |
$(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
|
117 |
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
|
118 |
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
|
119 |
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
|
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 |
} |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
122 |
// 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
|
123 |
// 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
|
124 |
$(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
|
125 |
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
|
126 |
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
|
127 |
} 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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
response(suggestions); |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
133 |
if((suggestions.length) == 0){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
134 |
methods.resetValues(instanceData); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
135 |
} |
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
|
136 |
}); |
8590d82e9b1b
[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 |
}; |
8590d82e9b1b
[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 |
} |
8590d82e9b1b
[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 |
$(this).autocomplete(settings); |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
140 |
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
|
141 |
$(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
|
142 |
} |
8590d82e9b1b
[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 |
}); |
8590d82e9b1b
[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 |
|
9388
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
146 |
_value: function() { |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
147 |
/* 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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
*/ |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
152 |
var settings = $(this.element).data('settings'); |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
153 |
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
|
154 |
if (settings.multiple & arguments.length === 0) { |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
155 |
return extractLast(value); |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
156 |
} |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
157 |
return value |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
158 |
}, |
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
159 |
|
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
|
160 |
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
|
161 |
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
|
162 |
// 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
|
163 |
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
|
164 |
}, |
8590d82e9b1b
[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 |
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
|
166 |
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
|
167 |
// 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
|
168 |
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
|
169 |
// 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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
}, |
8590d82e9b1b
[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 |
keydown: function(evt) { |
9388
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
175 |
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
|
176 |
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
|
177 |
} |
8590d82e9b1b
[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 |
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
|
180 |
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
|
181 |
// 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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
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
|
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 |
}; |
8590d82e9b1b
[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 |
}, |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
190 |
blur: function(evt){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
191 |
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
|
192 |
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
|
193 |
methods.resetValues(instanceData); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
194 |
} |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
195 |
}, |
9388
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
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 |
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
|
198 |
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
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
$(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
|
204 |
$(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
|
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 |
} |
8590d82e9b1b
[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 |
}, |
9388
4c34a63bd113
update jquery to 1.10 (closes #2786674)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9377
diff
changeset
|
208 |
|
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
209 |
resetValues: function(instanceData){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
210 |
$(instanceData.userInput).val(''); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
211 |
$(instanceData.hiddenInput).val(''); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
212 |
}, |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
213 |
|
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
|
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 |
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
|
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 |
* `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
|
218 |
* 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
|
219 |
* 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
|
220 |
* 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
|
221 |
* 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
|
222 |
* 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
|
223 |
* 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
|
224 |
* 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
|
225 |
* 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
|
226 |
**/ |
8590d82e9b1b
[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 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
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
|
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 |
|
8590d82e9b1b
[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 |
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
|
235 |
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
|
236 |
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
|
237 |
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
|
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 |
|
8590d82e9b1b
[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 |
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
|
241 |
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
|
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 |
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
|
244 |
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
|
245 |
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
|
246 |
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
|
247 |
name: userInput.name, |
6450
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
248 |
// 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
|
249 |
// 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
|
250 |
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
|
251 |
}); |
8590d82e9b1b
[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 |
$(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
|
253 |
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
|
254 |
$(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
|
255 |
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
|
256 |
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
|
257 |
}); |
8590d82e9b1b
[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 |
}, |
8590d82e9b1b
[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 |
|
8590d82e9b1b
[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 |
/* |
8590d82e9b1b
[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 |
* 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
|
262 |
* 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
|
263 |
* 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
|
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 |
* 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
|
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 |
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
|
268 |
// 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
|
269 |
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
|
270 |
$.isArray(suggestions[0])){ |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
271 |
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
|
272 |
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
|
273 |
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
|
274 |
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
|
275 |
}); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
276 |
} else { |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
}); |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
281 |
} |
c23639f26ec6
small typo on mustMach, handle initialvalue, handle empty userInput
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6448
diff
changeset
|
282 |
} |
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
|
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 |
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
|
285 |
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
|
286 |
&& !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
|
287 |
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
|
288 |
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
|
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 |
// 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
|
291 |
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
|
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 |
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
|
295 |
// 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
|
296 |
// 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
|
297 |
// 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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
302 |
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
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
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
|
307 |
} |
8590d82e9b1b
[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 |
} |
8590d82e9b1b
[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 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
310 |
} |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
311 |
}; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
312 |
|
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
313 |
$.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
|
314 |
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
|
315 |
}; |
8590d82e9b1b
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6372
diff
changeset
|
316 |
})(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
|
317 |
|
8590d82e9b1b
[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 |
|
0 | 319 |
Widgets.SuggestField = defclass('SuggestField', null, { |
320 |
__init__: function(node, options) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
321 |
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
|
322 |
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
|
323 |
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
|
324 |
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
|
325 |
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
|
326 |
$(node).cwautocomplete(data, options); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
327 |
}); |
0 | 328 |
} |
329 |
}); |
|
330 |
||
331 |
Widgets.StaticFileSuggestField = defclass('StaticSuggestField', [Widgets.SuggestField], { |
|
332 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
333 |
__init__: function(node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
334 |
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
|
335 |
method: 'get' // XXX |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
336 |
}); |
0 | 337 |
} |
338 |
||
339 |
}); |
|
340 |
||
341 |
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
|
342 |
__init__: function(node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
343 |
Widgets.SuggestField.__init__(this, node, { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
344 |
mustMatch: true |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
345 |
}); |
0 | 346 |
} |
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
|
347 |
}); |
0 | 348 |
|
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
349 |
//remote version of RestrictedSuggestField |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
350 |
Widgets.LazySuggestField = defclass('LazySuggestField', [Widgets.SuggestField], { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
351 |
__init__: function(node, options) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
352 |
var self = this; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
353 |
options = options || {}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
354 |
options.delay = 50; |
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
355 |
// 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
|
356 |
// initial values / display values) |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
357 |
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
|
358 |
if (!initialvalue) { |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
359 |
initialvalue = node.value; |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
360 |
} |
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
|
361 |
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
|
362 |
Widgets.SuggestField.__init__(this, node, options); |
4901
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
363 |
} |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
364 |
}); |
19ecbbc4f633
LazySuggestField : remote version of RestrictedSuggestField
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4738
diff
changeset
|
365 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
366 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
367 |
* .. function:: toggleTree(event) |
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 |
* called when the use clicks on a tree node |
0 | 370 |
* - if the node has a `cubicweb:loadurl` attribute, replace the content of the node |
371 |
* by the url's content. |
|
372 |
* - else, there's nothing to do, let the jquery plugin handle it. |
|
373 |
*/ |
|
374 |
function toggleTree(event) { |
|
375 |
var linode = jQuery(this); |
|
376 |
var url = linode.attr('cubicweb:loadurl'); |
|
377 |
if (url) { |
|
4738
6cca4f602486
fix open/close/open subnode bug #730709
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3079
diff
changeset
|
378 |
linode.find('ul.placeholder').remove(); |
9529
39b46b0b01e4
[web/data] fix treeview regression (closes #3526466)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9388
diff
changeset
|
379 |
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
|
380 |
d.addCallback(function(domnode) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
381 |
linode.removeAttr('cubicweb:loadurl'); |
9529
39b46b0b01e4
[web/data] fix treeview regression (closes #3526466)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9388
diff
changeset
|
382 |
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
|
383 |
toggle: toggleTree, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
384 |
prerendered: true |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
385 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
386 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
387 |
} |
9529
39b46b0b01e4
[web/data] fix treeview regression (closes #3526466)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9388
diff
changeset
|
388 |
); |
0 | 389 |
} |
390 |
} |
|
391 |
||
392 |
Widgets.TemplateTextField = defclass("TemplateTextField", null, { |
|
393 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
394 |
__init__: function(wdgnode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
395 |
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
|
396 |
this.options = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
397 |
name: wdgnode.getAttribute('cubicweb:inputid'), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
398 |
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
|
399 |
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
|
400 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
401 |
// this.variableRegexp = /%\((\w+)\)s/; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
402 |
this.errorField = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
403 |
'class': "errorMessage" |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
404 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
405 |
this.textField = TEXTAREA(this.options); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
406 |
jQuery(this.textField).bind('keyup', { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
407 |
'self': this |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
408 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
409 |
this.highlightInvalidVariables); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
410 |
jQuery('#substitutions').prepend(this.errorField); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
411 |
jQuery('#substitutions .errorMessage').hide(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
412 |
wdgnode.appendChild(this.textField); |
0 | 413 |
}, |
414 |
||
415 |
/* signal callbacks */ |
|
416 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
417 |
highlightInvalidVariables: function(event) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
418 |
var self = event.data.self; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
419 |
var text = self.textField.value; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
420 |
var unknownVariables = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
421 |
var it = 0; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
422 |
var group = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
423 |
var variableRegexp = /%\((\w+)\)s/g; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
424 |
// 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
|
425 |
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
|
426 |
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
|
427 |
unknownVariables.push(group[1]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
428 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
429 |
it++; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
430 |
if (it > 5) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
431 |
break; |
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 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
434 |
var errText = ''; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
435 |
if (unknownVariables.length) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
436 |
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
|
437 |
jQuery('#substitutions .errorMessage').show(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
438 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
439 |
jQuery('#substitutions .errorMessage').hide(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
440 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
441 |
self.errorField.innerHTML = errText; |
0 | 442 |
} |
443 |
||
444 |
}); |
|
445 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
446 |
cw.widgets = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
447 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
448 |
* .. function:: insertText(text, areaId) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
449 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
450 |
* 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
|
451 |
* 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
|
452 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
453 |
insertText: function (text, areaId) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
454 |
var textarea = jQuery('#' + areaId); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
455 |
if (document.selection) { // IE |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
456 |
var selLength; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
457 |
textarea.focus(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
458 |
var sel = document.selection.createRange(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
459 |
selLength = sel.text.length; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
460 |
sel.text = text; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
461 |
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
|
462 |
sel.select(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
463 |
} 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
|
464 |
var startPos = textarea.selectionStart; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
465 |
var endPos = textarea.selectionEnd; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
466 |
// 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
|
467 |
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
|
468 |
// 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
|
469 |
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
|
470 |
textarea.focus(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
471 |
} 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
|
472 |
textarea.value += text; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
473 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5453
diff
changeset
|
474 |
} |
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
|
475 |
}; |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
476 |
|
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
477 |
|
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
478 |
// 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
|
479 |
// 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
|
480 |
|
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
481 |
(function ($) { |
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
482 |
|
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
483 |
var methods = { |
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
484 |
__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
|
485 |
// closed over state |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
486 |
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
|
487 |
'$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
|
488 |
'name' : this.attr('id')}; |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
489 |
|
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
490 |
function sortoptions($optionlist) { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
491 |
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
|
492 |
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
|
493 |
}); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
494 |
// 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
|
495 |
$optionlist.append($sorted); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
496 |
}; |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
497 |
sortoptions(state.$fromNode); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
498 |
sortoptions(state.$toNode); |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
499 |
|
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
500 |
// 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
|
501 |
// 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
|
502 |
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
|
503 |
$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
|
504 |
var $option = $(option); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
505 |
// 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
|
506 |
$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
|
507 |
$option.text())); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
508 |
// 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
|
509 |
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
|
510 |
// 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
|
511 |
$option.remove(); |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
512 |
}); |
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
513 |
// 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
|
514 |
sortoptions($fromlist); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
515 |
sortoptions($tolist); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
516 |
}; |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
517 |
|
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
518 |
function addvalues () { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
519 |
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
|
520 |
// 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
|
521 |
var hiddenInput = INPUT({ |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
522 |
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
|
523 |
value : $option.val() |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
524 |
}); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
525 |
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
|
526 |
}); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
527 |
}; |
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
528 |
|
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
529 |
function removevalues () { |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
530 |
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
|
531 |
// 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
|
532 |
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
|
533 |
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
|
534 |
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
|
535 |
$(input).remove(); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
536 |
} |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
537 |
}); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
538 |
}); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
539 |
}; |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
540 |
|
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
541 |
var $this = $(this); |
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
542 |
$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
|
543 |
'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
|
544 |
$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
|
545 |
'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
|
546 |
|
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
547 |
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
|
548 |
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
|
549 |
|
6890
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
550 |
} |
1b2fcb9356a3
[widgets, js] add a InOutWidget for multiple select
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6739
diff
changeset
|
551 |
}; |
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
552 |
$.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
|
553 |
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
|
554 |
}; |
9377
4e0d8f06efbc
[js/widgets] fix the InOut widget with modern jQuery versions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8260
diff
changeset
|
555 |
})(jQuery); |