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 // plus re-set inline style ? |
|
22 jQuery('#' + divid).show(); |
|
23 jQuery('#' + divid + '-value').show(); |
|
24 jQuery('#' + divid + '-form').hide(); |
|
25 }, |
|
26 |
|
27 /* callback used on form validation success |
|
28 * refreshes the whole page or just the edited reledit zone |
|
29 * @param results: [status, ...] |
|
30 * @param formid: the dom id of the reledit form |
|
31 * @param cbargs: ... |
|
32 */ |
|
33 onSuccess: function (results, formid, cbargs) { |
|
34 var params = {fname: 'reledit_form'}; |
|
35 jQuery('#' + formid + ' input:hidden').each(function (elt) { |
|
36 var name = jQuery(this).attr('name'); |
|
37 if (name && name.startswith('__reledit|')) { |
|
38 params[name.split('|')[1]] = this.value; |
|
39 } |
|
40 }); |
|
41 var reload = cw.evalJSON(params.reload); |
|
42 if (reload || (params.formid == 'deleteconf')) { |
|
43 if (typeof reload == 'string') { |
|
44 /* Sometimes we want to reload but the reledit thing |
|
45 * updated a key attribute which was a component of the |
|
46 * url |
|
47 */ |
|
48 document.location.href = reload; |
|
49 return; |
|
50 } |
|
51 else { |
|
52 document.location.reload(); |
|
53 return; |
|
54 } |
|
55 } |
|
56 jQuery('#'+params.divid+'-reledit').loadxhtml(AJAX_BASE_URL, params, 'post', 'swap'); |
|
57 jQuery(cw).trigger('reledit-reloaded', params); |
|
58 }, |
|
59 |
|
60 /* called by reledit forms to submit changes |
|
61 * @param formid : the dom id of the form used |
|
62 * @param rtype : the attribute being edited |
|
63 * @param eid : the eid of the entity being edited |
|
64 * @param reload: boolean to reload page if true (when changing URL dependant data) |
|
65 * @param default_value : value if the field is empty |
|
66 */ |
|
67 loadInlineEditionForm: function(formid, eid, rtype, role, divid, reload, vid, action) { |
|
68 var args = {fname: 'reledit_form', rtype: rtype, role: role, |
|
69 pageid: pageid, action: action, |
|
70 eid: eid, divid: divid, formid: formid, |
|
71 reload: reload, vid: vid}; |
|
72 var d = jQuery('#'+divid+'-reledit').loadxhtml(AJAX_BASE_URL, args, 'post', 'swap'); |
|
73 d.addCallback(function () {cw.reledit.showInlineEditionForm(divid);}); |
|
74 } |
|
75 }); |
|