|
1 cw.reledit = new Namespace('cw.reledit'); |
|
2 |
|
3 |
|
4 jQuery.extend(cw.reledit, { |
|
5 |
|
6 /* Unhides the part of reledit div containing the form |
|
7 * hides other parts |
|
8 */ |
|
9 showInlineEditionForm: function (divid) { |
|
10 jQuery('#' + divid).hide(); |
|
11 jQuery('#' + divid + '-value').hide(); |
|
12 jQuery('#' + divid + '-form').show(); |
|
13 }, |
|
14 |
|
15 /* Hides and removes edition parts, incl. messages |
|
16 * show initial widget state |
|
17 */ |
|
18 cleanupAfterCancel: function (divid) { |
|
19 jQuery('#appMsg').hide(); |
|
20 jQuery('div.errorMessage').remove(); |
|
21 jQuery('#' + divid).show(); |
|
22 jQuery('#' + divid + '-value').show(); |
|
23 jQuery('#' + divid + '-form').hide(); |
|
24 }, |
|
25 |
|
26 /* callback used on form validation success |
|
27 * refreshes the whole page or just the edited reledit zone |
|
28 * @param results: [status, ...] |
|
29 * @param formid: the dom id of the reledit form |
|
30 * @param cbargs: ... |
|
31 */ |
|
32 onSuccess: function (results, formid, cbargs) { |
|
33 var params = {fname: 'reledit_form'}; |
|
34 jQuery('#' + formid + ' input:hidden').each(function (elt) { |
|
35 var name = jQuery(this).attr('name'); |
|
36 if (name && name.startswith('__reledit|')) { |
|
37 params[name.split('|')[1]] = this.value; |
|
38 } |
|
39 }); |
|
40 var reload = cw.evalJSON(params.reload); |
|
41 if (reload || (params.formid == 'deleteconf')) { |
|
42 if (typeof reload == 'string') { |
|
43 /* Sometimes we want to reload but the reledit thing |
|
44 * updated a key attribute which was a component of the |
|
45 * url |
|
46 */ |
|
47 document.location.href = reload; |
|
48 return; |
|
49 } |
|
50 else { |
|
51 document.location.reload(); |
|
52 return; |
|
53 } |
|
54 } |
|
55 jQuery('#'+params.divid+'-reledit').parent().loadxhtml(JSON_BASE_URL, params, 'post'); |
|
56 }, |
|
57 |
|
58 /* called by reledit forms to submit changes |
|
59 * @param formid : the dom id of the form used |
|
60 * @param rtype : the attribute being edited |
|
61 * @param eid : the eid of the entity being edited |
|
62 * @param reload: boolean to reload page if true (when changing URL dependant data) |
|
63 * @param default_value : value if the field is empty |
|
64 */ |
|
65 loadInlineEditionForm: function(formid, eid, rtype, role, divid, reload, vid, default_value) { |
|
66 var args = {fname: 'reledit_form', rtype: rtype, role: role, |
|
67 pageid: pageid, |
|
68 eid: eid, divid: divid, formid: formid, |
|
69 reload: reload, vid: vid, default_value: default_value, |
|
70 callback: function () {cw.reledit.showInlineEditionForm(divid);}}; |
|
71 jQuery('#'+divid+'-reledit').parent().loadxhtml(JSON_BASE_URL, args, 'post'); |
|
72 } |
|
73 }); |