author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Sat, 09 Oct 2010 00:05:52 +0200 | |
changeset 6427 | c8a5ac2d1eaa |
parent 6215 | 759cf097f5aa |
child 6448 | 8590d82e9b1b |
permissions | -rw-r--r-- |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
/** |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
* Functions for ajax boxes. |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
* |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
* :organization: Logilab |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
* :copyright: 2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
* :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
* |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
*/ |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
|
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
function ajaxBoxValidateSelectorInput(boxid, eid, separator, fname, msg) { |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
var holderid = cw.utils.domid(boxid) + eid + 'Holder'; |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
var value = $('#' + holderid + 'Input').val(); |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
if (separator) { |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
14 |
value = $.map(value.split(separator), jQuery.trim); |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
} |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
16 |
var d = loadRemote('json', ajaxFuncArgs(fname, null, eid, value)); |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
17 |
d.addCallback(function() { |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
18 |
$('#' + holderid).empty(); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
19 |
var formparams = ajaxFuncArgs('render', null, 'boxes', boxid, eid); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
20 |
$('#' + cw.utils.domid(boxid) + eid).loadxhtml('json', formparams); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
21 |
if (msg) { |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
22 |
document.location.hash = '#header'; |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
23 |
updateMessage(msg); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
24 |
} |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
25 |
}); |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
26 |
} |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
27 |
|
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
28 |
function ajaxBoxRemoveLinkedEntity(boxid, eid, relatedeid, delfname, msg) { |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
29 |
var d = loadRemote('json', ajaxFuncArgs(delfname, null, eid, relatedeid)); |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
30 |
d.addCallback(function() { |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
31 |
var formparams = ajaxFuncArgs('render', null, 'boxes', boxid, eid); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
32 |
$('#' + cw.utils.domid(boxid) + eid).loadxhtml('json', formparams); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
33 |
if (msg) { |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
34 |
document.location.hash = '#header'; |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
35 |
updateMessage(msg); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
36 |
} |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
37 |
}); |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
38 |
} |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
39 |
|
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
40 |
function ajaxBoxShowSelector(boxid, eid, |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
41 |
unrelfname, |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
42 |
addfname, msg, |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
43 |
oklabel, cancellabel, |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
44 |
separator) { |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
45 |
var holderid = cw.utils.domid(boxid) + eid + 'Holder'; |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
46 |
var holder = $('#' + holderid); |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
47 |
if (holder.children().length) { |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
48 |
holder.empty(); |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
49 |
} |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
50 |
else { |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
51 |
var inputid = holderid + 'Input'; |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
52 |
var deferred = loadRemote('json', ajaxFuncArgs(unrelfname, null, eid)); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
53 |
deferred.addCallback(function (unrelated) { |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
54 |
var input = INPUT({'type': 'text', 'id': inputid, 'size': 20}); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
55 |
holder.append(input).show(); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
56 |
$input = $(input); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
57 |
$input.keypress(function (event) { |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
58 |
if (event.keyCode == KEYS.KEY_ENTER) { |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
59 |
// XXX not very user friendly: we should test that the suggestions |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
60 |
// aren't visible anymore |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
61 |
ajaxBoxValidateSelectorInput(boxid, eid, separator, addfname, msg); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
62 |
} |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
63 |
}); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
64 |
var buttons = DIV({'class' : "sgformbuttons"}, |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
65 |
A({'href' : "javascript: noop();", |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
66 |
'onclick' : cw.utils.strFuncCall('ajaxBoxValidateSelectorInput', |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
67 |
boxid, eid, separator, addfname, msg)}, |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
68 |
oklabel), |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
69 |
' / ', |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
70 |
A({'href' : "javascript: noop();", |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
71 |
'onclick' : '$("#' + holderid + '").empty()'}, |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
72 |
cancellabel)); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
73 |
holder.append(buttons); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
74 |
$input.autocomplete(unrelated, { |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
75 |
multiple: separator, |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
76 |
max: 15 |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
77 |
}); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
78 |
$input.focus(); |
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5949
diff
changeset
|
79 |
}); |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
80 |
} |
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
81 |
} |