source: products/quintagroup.referencedatagridfield/trunk/quintagroup/referencedatagridfield/skins/referencedatagridfield/referencebrowser.js @ 2360

Last change on this file since 2360 was 2360, checked in by mylan, 14 years ago

Toggle trunk for plone4 release.
Plone-3 release moved to brances/plone3.

Merged revisions 3345-3351,3355-3359,3361-3370,3372-3390,3397 via svnmerge from
http://svn.quintagroup.com/products/quintagroup.referencedatagridfield/branches/plone4

Fixed minor conflicts in:

  • ./setup.py
  • ./quintagroup/referencedatagridfield/configure.zcml

........

r3345 | mylan | 2010-05-13 15:51:53 +0300 (Thu, 13 May 2010) | 1 line


Update requirements: in setup.py, included its in configure.zcml

........

r3346 | mylan | 2010-05-13 17:42:07 +0300 (Thu, 13 May 2010) | 1 line


Added refdatagridbrowser_popup view with popup customization for the referencedatagridfield

........

r3347 | mylan | 2010-05-13 17:50:14 +0300 (Thu, 13 May 2010) | 1 line


Added and registered datagridref_popup named template for the ReferenceDataGridWidget?

........

r3348 | mylan | 2010-05-13 18:59:34 +0300 (Thu, 13 May 2010) | 1 line


Fix typo in named_template_adapter

........

r3349 | mylan | 2010-05-13 19:00:21 +0300 (Thu, 13 May 2010) | 1 line


Prevent breakage of datagridwidget_manipulators.pt

........

r3350 | mylan | 2010-05-13 20:01:59 +0300 (Thu, 13 May 2010) | 1 line


Initial reference popup integration

........

r3351 | mylan | 2010-05-13 22:05:47 +0300 (Thu, 13 May 2010) | 1 line


Update default referencebrowser javascript / datagrid field to popup work correctly for new added row

........

r3355 | mylan | 2010-05-14 17:21:23 +0300 (Fri, 14 May 2010) | 1 line


Fix reference browser url calculation on the view - pass additional paramters

........

r3356 | mylan | 2010-05-14 17:26:49 +0300 (Fri, 14 May 2010) | 1 line


Update datagridwidget_manipulators template for additional params pass to datagridref_popup view

........

r3357 | mylan | 2010-05-14 17:27:59 +0300 (Fri, 14 May 2010) | 1 line


Remove order_idx from the additional parmeters - it will be calulated with jQuery

........

r3358 | mylan | 2010-05-14 17:29:20 +0300 (Fri, 14 May 2010) | 1 line


Updated jQuery processor on UID adding

........

r3359 | mylan | 2010-05-14 17:31:54 +0300 (Fri, 14 May 2010) | 1 line


Added focus and blur event-handlers to referencedatagridwidget javascripts

........

r3361 | mylan | 2010-05-17 18:08:44 +0300 (Mon, 17 May 2010) | 1 line


Fixed all overlays bindings to same target issue

........

r3362 | mylan | 2010-05-17 18:29:07 +0300 (Mon, 17 May 2010) | 1 line


Fix error with everlay windows autoclosing

........

r3363 | mylan | 2010-05-17 18:29:51 +0300 (Mon, 17 May 2010) | 1 line


Fix error with everlay windows autoclosing

........

r3364 | mylan | 2010-05-17 18:35:25 +0300 (Mon, 17 May 2010) | 1 line


Fixed link, title and uid data set in refbrowser_setReference

........

r3365 | mylan | 2010-05-17 18:38:15 +0300 (Mon, 17 May 2010) | 1 line


Fix error with everlay windows autoclosing

........

r3366 | mylan | 2010-05-17 18:43:18 +0300 (Mon, 17 May 2010) | 1 line


Fix addReferenceDataGridRowAfter newly added method of dataGridFieldFunctions

........

r3367 | mylan | 2010-05-17 18:46:10 +0300 (Mon, 17 May 2010) | 1 line


Implemented addReferenceDataGridRowAfter method of dataGridFieldFunctions object

........

r3368 | mylan | 2010-05-17 18:47:22 +0300 (Mon, 17 May 2010) | 1 line


Override updateOrderIndex method of dataGridFieldFunctions

........

r3369 | mylan | 2010-05-17 19:14:01 +0300 (Mon, 17 May 2010) | 1 line


Fixed styles toggling on title column edition

........

r3370 | mylan | 2010-05-17 20:35:10 +0300 (Mon, 17 May 2010) | 1 line


Little clean-up

........

r3372 | mylan | 2010-05-18 19:02:12 +0300 (Tue, 18 May 2010) | 1 line


Fix Deprication warning for plone4 consider importing

........

r3373 | mylan | 2010-05-18 19:04:12 +0300 (Tue, 18 May 2010) | 1 line


Added base tests structure, move tests into the tests package

........

r3374 | mylan | 2010-05-18 19:04:51 +0300 (Tue, 18 May 2010) | 1 line


Added installation tests

........

r3375 | mylan | 2010-05-18 20:08:00 +0300 (Tue, 18 May 2010) | 1 line


Fixed package installation, updated demo content creation to MixIn? class

........

r3376 | mylan | 2010-05-18 22:20:41 +0300 (Tue, 18 May 2010) | 1 line


Added basic field test

........

r3377 | mylan | 2010-05-18 23:29:24 +0300 (Tue, 18 May 2010) | 1 line


Added test for link, uid, title for the field

........

r3378 | mylan | 2010-05-19 10:54:46 +0300 (Wed, 19 May 2010) | 1 line


Prevent changing security manager on tested content adding

........

r3379 | mylan | 2010-05-19 13:58:29 +0300 (Wed, 19 May 2010) | 1 line


Added tests for possible bugs in field processing

........

r3380 | mylan | 2010-05-19 13:58:54 +0300 (Wed, 19 May 2010) | 1 line


Updated testing content creation

........

r3381 | mylan | 2010-05-19 13:59:49 +0300 (Wed, 19 May 2010) | 1 line


Simplify field name for example content type

........

r3382 | mylan | 2010-05-19 14:01:16 +0300 (Wed, 19 May 2010) | 1 line


Fixed bug on getting data for uninitialized field

........

r3383 | mylan | 2010-05-19 15:22:37 +0300 (Wed, 19 May 2010) | 1 line


Added tests for widget in view mode

........

r3384 | mylan | 2010-05-19 16:47:06 +0300 (Wed, 19 May 2010) | 1 line


Update comments for TestWidgetView?, some code cleanup

........

r3385 | mylan | 2010-05-19 17:02:29 +0300 (Wed, 19 May 2010) | 1 line


Added TestWidgetEditPresence? tests for presence of columns and buttons in edit mode of the widget

........

r3386 | mylan | 2010-05-19 18:00:01 +0300 (Wed, 19 May 2010) | 1 line


Remove records with links to unexistent objects on getting data from the field

........

r3387 | mylan | 2010-05-19 18:13:57 +0300 (Wed, 19 May 2010) | 1 line


Minor changes

........

r3388 | mylan | 2010-05-19 18:14:42 +0300 (Wed, 19 May 2010) | 1 line


Added tests popup related adapters registration

........

r3389 | mylan | 2010-05-19 19:10:49 +0300 (Wed, 19 May 2010) | 1 line


Added tests for pupup related staff in edit mode of ReferenceDataGridWidget?

........

r3390 | mylan | 2010-05-19 19:12:06 +0300 (Wed, 19 May 2010) | 1 line


Added tests of widget resources

........

r3397 | mylan | 2010-05-19 21:02:51 +0300 (Wed, 19 May 2010) | 1 line


Added MANIFEST.in, updated author in package information

........

File size: 12.5 KB
Line 
1function prepareRefPopup(context) {
2    jq(function() {
3
4      // the overlay itself
5      jq('.addreference', context).overlay({
6           closeOnClick: false,
7           onBeforeLoad: function() {
8               ov = jq('div#content').data('overlay');
9               // close overlay, if there is one already
10               // we only allow one referencebrowser per time
11               if (ov) {ov.close(); }
12               var wrap = this.getContent().find('.overlaycontent');
13               var src = this.getTrigger().attr('src');
14               var srcfilter = src + ' >*';
15               wrap.data('srcfilter', srcfilter);
16               jq('div#content').data('overlay', this);
17               resetHistory();
18               wrap.load(srcfilter);
19               },
20           onLoad: function() {
21               widget_id = this.getTrigger().attr('rel').substring(6);
22               disablecurrentrelations(widget_id);
23           }});
24
25      // the breadcrumb-links and the links of the 'tree'-navigation
26      jq('[id^=atrb_] a.browsesite', context).live('click', function(event) {
27          var target = jq(this);
28          var src = target.attr('href');
29          var wrap = target.parents('.overlaycontent');
30          var srcfilter = src + ' >*';
31          pushToHistory(wrap.data('srcfilter'));
32          wrap.data('srcfilter', srcfilter);
33          // the history we are constructing here is destinct from the
34          // srcfilter-history. here we construct a selection-widget, which
35          // is available, if the history_length-parameter is set on the widget
36          // the srcfilter-history is used for storing the URLs to make the
37          // 'Back'-link work.
38          var newoption = '<option value="' + src + '">' + target.attr('rel') + '</option>';
39          refreshOverlay(wrap, srcfilter, newoption);
40          return false;
41          });
42
43      // the links for inserting referencens
44      jq('[id^=atrb_] input.insertreference', context).live('click', function(event) {
45          var target = jq(this);
46          var wrap = target.parents('.overlaycontent');
47          var fieldname = wrap.find('input[name=fieldName]').attr('value');
48          var fieldtitle = wrap.find('input[name=fieldTitleName]').attr('value');
49          var fieldlink = wrap.find('input[name=fieldLinkName]').attr('value');
50          var multi = wrap.find('input[name=multiValued]').attr('value');
51          var close_window = wrap.find('input[name=close_window]').attr('value');
52          var title = target.parents('tr').find('img').attr('alt');
53          var linkpath = target.parents('tr').find('img').attr('rel');
54          var active_tr = wrap.parents('tr[id=datagridwidget-row]');
55          var uid = target.attr('rel');
56          refbrowser_setReference(fieldname, uid, title, parseInt(multi),
57                                  active_tr, fieldtitle, title, fieldlink, linkpath);
58          if (close_window === '1') {
59              overlay = jq('div#content').data('overlay');
60              overlay.close();
61          } else {
62              showMessage(title);
63          };
64          jq(this).attr('disabled', 'disabled');
65          });
66
67
68      // the history menu
69      jq('[id^=atrb_] form#history select[name=path]', context).live('change', function(event) {
70          var target = jq(this);
71          var wrap = target.parents('.overlaycontent');
72          src = jq('[id^=atrb_] form#history select[name=path] :selected', this).attr('value');
73          var srcfilter = src + ' >*';
74          refreshOverlay(wrap, srcfilter, '');
75          return false;
76          });
77
78      // the search form
79      jq('[id^=atrb_] form#search input[name=submit]', context).live('click', function(event) {
80          var target = jq(this);
81          var src = target.parents('form').attr('action');
82          var wrap = target.parents('.overlaycontent');
83          var fieldname = wrap.find('input[name=fieldName]').attr('value');
84          var fieldtitle = wrap.find('input[name=fieldTitleName]').attr('value');
85          var fieldlink = wrap.find('input[name=fieldLinkName]').attr('value');
86          var fieldrealname = wrap.find('input[name=fieldRealName]').attr('value');
87          var at_url = wrap.find('input[name=at_url]').attr('value');
88          var searchvalue = wrap.find('input[name=searchValue]').attr('value');
89          var multi = wrap.find('input[name=multiValued]').attr('value');
90          var close_window = wrap.find('input[name=close_window]').attr('value');
91          qs = 'searchValue=' + searchvalue + '&fieldRealName=' + fieldrealname +
92            '&fieldName=' + fieldname + '&multiValued=' + multi +
93            '&close_window=' + close_window + '&at_url=' + at_url +
94            '&fieldTitleName=' + fieldtitle + '&fieldLinkName=' + fieldlink;
95          var srcfilter = src + '?' + qs + ' >*';
96          pushToHistory(wrap.data('srcfilter'));
97          wrap.data('srcfilter', srcfilter);
98          refreshOverlay(wrap, srcfilter, '');
99          return false;
100          });
101
102    });
103};
104
105jq(document).ready(function(){
106    prepareRefPopup(this);
107});
108jq.fn.prepRefPopup = function() {
109    prepareRefPopup(this);
110};
111
112function disablecurrentrelations (widget_id) {
113   jq('ul#' + widget_id + ' :input').each(
114       function (intIndex) {
115         uid = jq(this).attr('value');
116         cb = jq('input[rel=' + uid + ']');
117         cb.attr('disabled', 'disabled');
118         cb.attr('checked', 'checked');
119       });
120}
121
122// function to return a reference from the popup window back into the widget
123function refbrowser_setReference(widget_id, uid, label, multi,
124                                 active_tr, widget_title_id, link_title,
125                                 widget_link_id, link_path)
126{
127    var element = null,
128        label_element = null,
129        current_values = null,
130        i = null,
131        list = null,
132        li = null,
133        input = null,
134        up_element = null,
135        down_element = null,
136        container = null;
137
138    if (typeof(active_tr) != "undefined") {
139        // Update Uid field
140        jq('#' + widget_id, active_tr).attr("value", uid);
141        // Update title field
142        title = jq('#' + widget_title_id, active_tr);
143        title.attr("value", link_title);
144        title.addClass("not-changed-title-field");
145        title.attr("default_value", link_title);
146        title.blur(triggerTitleClass);
147        title.focus(triggerOnFocusStyles);
148        // Update link field
149        link = jq('#' + widget_link_id, active_tr);
150        link.attr('readonly', false);
151        link.attr('value', link_path);
152        link.attr('readonly', true);
153        link.addClass("hidden-field");
154
155    } else if (multi === 0) {
156        // differentiate between the single and mulitselect widget
157        // since the single widget has an extra label field.
158        jq('#' + widget_id).attr('value', uid);
159        jq('#' + widget_id + '_label').attr('value', label);
160    }  else {
161        // check if the item isn't already in the list
162        current_values = jq('#' + widget_id + ' input');
163        for (i = 0; i < current_values.length; i++) {
164            if (current_values[i].value === uid) {
165                return false;
166            }
167        }
168        // now add the new item
169        list = document.getElementById(widget_id);
170        // add ul-element to DOM, if it is not there
171        if (list === null) {
172            container = jq('#archetypes-fieldname-' + widget_id + ' input + div');
173            if (!container.length) {
174                // fix for Plone 3.3 collections, with a weird widget-id
175                container = jq('#archetypes-fieldname-value input + div');
176            }
177            container.after(
178               '<ul class="visualNoMarker" id="' + widget_id + '"></ul>');
179            list = document.getElementById(widget_id);
180        }
181        li = document.createElement('li');
182        label_element = document.createElement('label');
183        input = document.createElement('input');
184        input.type = 'checkbox';
185        input.value = uid;
186        input.checked = true;
187        input.name = widget_id + ':list';
188        label_element.appendChild(input);
189        label_element.appendChild(document.createTextNode(' ' + label));
190        li.appendChild(label_element);
191        li.id = 'ref-' + widget_id + '-' + current_values.length;
192
193        sortable = jq('input[name=' + widget_id + '-sortable]').attr('value');
194        if (sortable === '1') {
195          up_element = document.createElement('a');
196          up_element.title = 'Move Up';
197          up_element.innerHTML = '&#x25b2;';
198          up_element.onclick = function () {
199              refbrowser_moveReferenceUp(this);
200              return false;
201          };
202
203          li.appendChild(up_element);
204
205          down_element = document.createElement('a');
206          down_element.title = 'Move Down';
207          down_element.innerHTML = '&#x25bc;';
208          down_element.onclick = function () {
209              refbrowser_moveReferenceDown(this);
210              return false;
211          };
212
213          li.appendChild(down_element);
214        }
215        list.appendChild(li);
216
217        // fix on IE7 - check *after* adding to DOM
218        input.checked = true;
219    }
220}
221
222// function to clear the reference field or remove items
223// from the multivalued reference list.
224function refbrowser_removeReference(widget_id, multi)
225{
226    var x = null,
227        element = null,
228        label_element = null,
229        list = null;
230
231    if (multi) {
232        list = document.getElementById(widget_id);
233        for (x = list.length - 1; x >= 0; x--) {
234            if (list[x].selected) {
235                list[x] = null;
236            }
237        }
238        for (x = 0; x < list.length; x++) {
239            list[x].selected = 'selected';
240        }
241    } else {
242        jq('#' + widget_id).attr('value', "");
243        jq('#' + widget_id + '_label').attr('value', "");
244    }
245}
246
247function refbrowser_moveReferenceUp(self)
248{
249    var elem = self.parentNode,
250        eid = null,
251        pos = null,
252        widget_id = null,
253        newelem = null,
254        prevelem = null,
255        arrows = null,
256        cbs = null;
257    if (elem === null) {
258        return false;
259    }
260    eid = elem.id.split('-');
261    pos = eid.pop();
262    if (pos === 0) {
263        return false;
264    }
265    widget_id = eid.pop();
266    newelem = elem.cloneNode(true);
267
268    //Fix: (IE keep the standard value)
269    cbs = newelem.getElementsByTagName("input");
270    if (cbs.length > 0) {
271        cbs[0].checked = elem.getElementsByTagName("input")[0].checked;
272    }
273
274    prevelem = document.getElementById('ref-' + widget_id + '-' + (pos - 1));
275
276    // up arrow
277    arrows = newelem.getElementsByTagName("a");
278    arrows[0].onclick = function () {
279        refbrowser_moveReferenceUp(this);
280    };
281    // down arrow
282    arrows[1].onclick = function () {
283        refbrowser_moveReferenceDown(this);
284    };
285
286    elem.parentNode.insertBefore(newelem, prevelem);
287    elem.parentNode.removeChild(elem);
288    newelem.id = 'ref-' + widget_id + '-' + (pos - 1);
289    prevelem.id = 'ref-' + widget_id + '-' + pos;
290}
291
292function refbrowser_moveReferenceDown(self)
293{
294    var elem = self.parentNode,
295        eid = null,
296        pos = null,
297        widget_id = null,
298        current_values = null,
299        newelem = null,
300        nextelem = null,
301        cbs = null,
302        arrows = null;
303    if (elem === null) {
304        return false;
305    }
306    eid = elem.id.split('-');
307    pos = parseInt(eid.pop(), 10);
308    widget_id = eid.pop();
309    current_values = jq('#' + widget_id + ' input');
310    if ((pos + 1) === current_values.length) {
311        return false;
312    }
313
314    newelem = elem.cloneNode(true);
315    //Fix: (IE keep the standard value)
316    cbs = newelem.getElementsByTagName("input");
317    if (cbs.length > 0) {
318        cbs[0].checked = elem.getElementsByTagName("input")[0].checked;
319    }
320
321    // up img
322    arrows = newelem.getElementsByTagName("a");
323    arrows[0].onclick = function () {
324        refbrowser_moveReferenceUp(this);
325    };
326    // down img
327    arrows[1].onclick = function () {
328        refbrowser_moveReferenceDown(this);
329    };
330
331    nextelem = document.getElementById('ref-' + widget_id + '-' + (pos + 1));
332
333    elem.parentNode.insertBefore(newelem, nextelem.nextSibling);
334    elem.parentNode.removeChild(elem);
335    newelem.id = 'ref-' + widget_id + '-' + (pos + 1);
336    nextelem.id = 'ref-' + widget_id + '-' + pos;
337}
338
339function showMessage(message) {
340    jq('#messageTitle').text(message);
341    jq('#message').show();
342}
343
344function submitHistoryForm() {
345     var form = document.history;
346     var path = form.path.options[form.path.selectedIndex].value;
347     form.action = path;
348     form.submit();
349}
350
351function pushToHistory(url) {
352  var history = jq(document).data('atrb_history');
353  history.push(url);
354  jq(document).data('atrb_history', history);
355}
356
357function resetHistory() {
358  jq(document).data('atrb_history', []);
359}
360
361function popFromHistory() {
362  var history = jq(document).data('atrb_history');
363  value = history.pop();
364  jq(document).data('atrb_history', history);
365  return value;
366}
367
368function refreshOverlay(wrap, srcfilter, newoption) {
369    var oldhistory = jq('[id^=atrb_] form#history select');
370    wrap.load(srcfilter, function() { 
371        jq('[id^=atrb_] form#history select').append(newoption + oldhistory.html());
372        ov = jq('div#content').data('overlay');
373        widget_id = ov.getTrigger().attr('rel').substring(6);
374        disablecurrentrelations(widget_id);
375        });
376}
Note: See TracBrowser for help on using the repository browser.