r13406 - in MoreFieldsAndWidgets/archetypes.referencebrowserwidget/trunk: docs src/archetypes/referencebrowserwidget/skins/referencebrowser

"Carsten Senger" <[email protected]>
Newsgroups gmane.comp.web.zope.plone.archetypes.cvs
Message-ID <[email protected]>
Author: csenger
Date: Tue Jan 11 14:43:43 2011
New Revision: 13406

Modified:
   MoreFieldsAndWidgets/archetypes.referencebrowserwidget/trunk/docs/CHANGES.txt
   MoreFieldsAndWidgets/archetypes.referencebrowserwidget/trunk/src/archetypes/referencebrowserwidget/skins/referencebrowser/referencebrowser.js
Log:
check the references in the overlay that are checked in the widget
when the overlay is constructed or refreshed.


Modified: MoreFieldsAndWidgets/archetypes.referencebrowserwidget/trunk/docs/CHANGES.txt
==============================================================================
--- MoreFieldsAndWidgets/archetypes.referencebrowserwidget/trunk/docs/CHANGES.txt	(original)
+++ MoreFieldsAndWidgets/archetypes.referencebrowserwidget/trunk/docs/CHANGES.txt	Tue Jan 11 14:43:43 2011
@@ -4,6 +4,10 @@
 2.2 - Unreleased
 ----------------
 
+* check the references in the overlay that are checked in the widget
+  when the overlay is constructed or refreshed.
+  [csenger]
+
 * Don't disable checkboxes in overlay when an item is selected.
   Remove the item from the value list when it is unchecked in
   the value list. Partly fixes http://dev.plone.org/plone/ticket/10786

Modified: MoreFieldsAndWidgets/archetypes.referencebrowserwidget/trunk/src/archetypes/referencebrowserwidget/skins/referencebrowser/referencebrowser.js
==============================================================================
--- MoreFieldsAndWidgets/archetypes.referencebrowserwidget/trunk/src/archetypes/referencebrowserwidget/skins/referencebrowser/referencebrowser.js	(original)
+++ MoreFieldsAndWidgets/archetypes.referencebrowserwidget/trunk/src/archetypes/referencebrowserwidget/skins/referencebrowser/referencebrowser.js	Tue Jan 11 14:43:43 2011
@@ -13,7 +13,10 @@
            wrap.data('srcfilter', srcfilter);
            jq('div#content').data('overlay', this);
            resetHistory();
-           wrap.load(srcfilter);
+           wrap.load(srcfilter, function() {
+               var fieldname = wrap.find('input[name=fieldName]').attr('value');
+               check_referenced_items(fieldname);
+               });
            },
        onLoad: function() {
            widget_id = this.getTrigger().attr('rel').substring(6);
@@ -53,7 +56,7 @@
                                   uid, title, parseInt(multi));
           }
       else {
-          refbrowser_delReference('ref_browser_' + fieldname, uid);
+          refbrowser_delReference(fieldname, uid);
       }
       if (close_window === '1') {
           overlay = jq('div#content').data('overlay');
@@ -199,14 +202,13 @@
     }
 }
 
-
 // remove the item for the uid from the reference widget
-function refbrowser_delReference(widget_id, uid) {
-    var input= jq('#' + widget_id + ' input[value="' + uid + '"]');
-    input.closest('li').remove();
+function refbrowser_delReference(fieldname, uid) {
+    var selector = 'input[value="' + uid + '"][name="' + fieldname + ':list"]',
+        inputs = jq(selector);
+    inputs.closest('li').remove();
 }
 
-
 // function to clear the reference field or remove items
 // from the multivalued reference list.
 function refbrowser_removeReference(widget_id, multi)
@@ -361,5 +363,33 @@
         ov = jq('div#content').data('overlay');
         widget_id = ov.getTrigger().attr('rel').substring(6);
         disablecurrentrelations(widget_id);
+        var fieldname = wrap.find('input[name=fieldName]').attr('value');
+        check_referenced_items(fieldname);
         });
 }
+
+// check all references in the overlay that are present in the widget
+function check_referenced_items(fieldname) {
+    var refs_in_overlay = jq('input.insertreference'),
+        uid_selector = "input[name='" + fieldname + ":list']",
+        current = jq(uid_selector), // the widget in the form
+        current_uids = current.map(function () {
+            if (jq(this).attr('checked') === true) {
+                return jq(this).attr('value');
+            }
+            return null;
+        });
+
+    refs_in_overlay.each(function () {
+        var overlay_ref = jq(this),
+            uid = jq(overlay_ref).attr('rel'),
+            i;
+
+        for (i = 0; i < current_uids.length; i++) {
+            if (uid === current_uids[i]) {
+                overlay_ref.attr('checked', true);
+                return true;  // break jq.each
+            }
+        }
+    });
+}
\ No newline at end of file

------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web.   Learn how to 
best implement a security strategy that keeps consumers' information secure 
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.