function prepareRefPopup(context) { jq(function() { // the overlay itself jq('.addreference', context).overlay({ closeOnClick: false, onBeforeLoad: function() { ov = jq('div#content').data('overlay'); // close overlay, if there is one already // we only allow one referencebrowser per time if (ov) {ov.close(); } var wrap = this.getContent().find('.overlaycontent'); var src = this.getTrigger().attr('src'); var srcfilter = src + ' >*'; wrap.data('srcfilter', srcfilter); jq('div#content').data('overlay', this); resetHistory(); wrap.load(srcfilter); }, onLoad: function() { widget_id = this.getTrigger().attr('rel').substring(6); disablecurrentrelations(widget_id); }}); // the breadcrumb-links and the links of the 'tree'-navigation jq('[id^=atrb_] a.browsesite', context).live('click', function(event) { var target = jq(this); var src = target.attr('href'); var wrap = target.parents('.overlaycontent'); var srcfilter = src + ' >*'; pushToHistory(wrap.data('srcfilter')); wrap.data('srcfilter', srcfilter); // the history we are constructing here is destinct from the // srcfilter-history. here we construct a selection-widget, which // is available, if the history_length-parameter is set on the widget // the srcfilter-history is used for storing the URLs to make the // 'Back'-link work. var newoption = ''; refreshOverlay(wrap, srcfilter, newoption); return false; }); // the links for inserting referencens jq('[id^=atrb_] input.insertreference', context).live('click', function(event) { var target = jq(this); var wrap = target.parents('.overlaycontent'); var fieldname = wrap.find('input[name=fieldName]').attr('value'); var fieldtitle = wrap.find('input[name=fieldTitleName]').attr('value'); var fieldlink = wrap.find('input[name=fieldLinkName]').attr('value'); var multi = wrap.find('input[name=multiValued]').attr('value'); var close_window = wrap.find('input[name=close_window]').attr('value'); var title = target.parents('tr').find('img').attr('alt'); var linkpath = target.parents('tr').find('img').attr('rel'); var active_tr = wrap.parents('tr[id=datagridwidget-row]'); var uid = target.attr('rel'); refbrowser_setReference(fieldname, uid, title, parseInt(multi), active_tr, fieldtitle, title, fieldlink, linkpath); if (close_window === '1') { overlay = jq('div#content').data('overlay'); overlay.close(); } else { showMessage(title); }; jq(this).attr('disabled', 'disabled'); }); // the history menu jq('[id^=atrb_] form#history select[name=path]', context).live('change', function(event) { var target = jq(this); var wrap = target.parents('.overlaycontent'); src = jq('[id^=atrb_] form#history select[name=path] :selected', this).attr('value'); var srcfilter = src + ' >*'; refreshOverlay(wrap, srcfilter, ''); return false; }); // the search form jq('[id^=atrb_] form#search input[name=submit]', context).live('click', function(event) { var target = jq(this); var src = target.parents('form').attr('action'); var wrap = target.parents('.overlaycontent'); var fieldname = wrap.find('input[name=fieldName]').attr('value'); var fieldtitle = wrap.find('input[name=fieldTitleName]').attr('value'); var fieldlink = wrap.find('input[name=fieldLinkName]').attr('value'); var fieldrealname = wrap.find('input[name=fieldRealName]').attr('value'); var at_url = wrap.find('input[name=at_url]').attr('value'); var searchvalue = wrap.find('input[name=searchValue]').attr('value'); var multi = wrap.find('input[name=multiValued]').attr('value'); var close_window = wrap.find('input[name=close_window]').attr('value'); qs = 'searchValue=' + searchvalue + '&fieldRealName=' + fieldrealname + '&fieldName=' + fieldname + '&multiValued=' + multi + '&close_window=' + close_window + '&at_url=' + at_url + '&fieldTitleName=' + fieldtitle + '&fieldLinkName=' + fieldlink; var srcfilter = src + '?' + qs + ' >*'; pushToHistory(wrap.data('srcfilter')); wrap.data('srcfilter', srcfilter); refreshOverlay(wrap, srcfilter, ''); return false; }); }); }; jq(document).ready(function(){ prepareRefPopup(this); }); jq.fn.prepRefPopup = function() { prepareRefPopup(this); }; function disablecurrentrelations (widget_id) { jq('ul#' + widget_id + ' :input').each( function (intIndex) { uid = jq(this).attr('value'); cb = jq('input[rel=' + uid + ']'); cb.attr('disabled', 'disabled'); cb.attr('checked', 'checked'); }); } // function to return a reference from the popup window back into the widget function refbrowser_setReference(widget_id, uid, label, multi, active_tr, widget_title_id, link_title, widget_link_id, link_path) { var element = null, label_element = null, current_values = null, i = null, list = null, li = null, input = null, up_element = null, down_element = null, container = null; if (typeof(active_tr) != "undefined" && typeof(link_title) != "undefined" && typeof(link_path) != "undefined" && typeof(widget_title_id) != "undefined" && typeof(widget_link_id) != "undefined") { // Update Uid field jq('#' + widget_id, active_tr).attr("value", uid); // Update title field title = jq('#' + widget_title_id, active_tr); title.attr("value", link_title); title.addClass("not-changed-title-field"); title.attr("default_value", link_title); title.blur(triggerTitleClass); title.focus(triggerOnFocusStyles); // Update link field link = jq('#' + widget_link_id, active_tr); link.attr('readonly', false); link.attr('value', link_path); link.attr('readonly', true); link.addClass("hidden-field"); } else if (multi === 0) { // differentiate between the single and mulitselect widget // since the single widget has an extra label field. jq('#' + widget_id).attr('value', uid); jq('#' + widget_id + '_label').attr('value', label); } else { // check if the item isn't already in the list current_values = jq('#' + widget_id + ' input'); for (i = 0; i < current_values.length; i++) { if (current_values[i].value === uid) { return false; } } // now add the new item list = document.getElementById(widget_id); // add ul-element to DOM, if it is not there if (list === null) { container = jq('#archetypes-fieldname-' + widget_id + ' input + div'); if (!container.length) { // fix for Plone 3.3 collections, with a weird widget-id container = jq('#archetypes-fieldname-value input + div'); } container.after( '