diff --git a/CHANGES.rst b/CHANGES.rst index 1f2af0d..46f2f3e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,12 @@ Changelog 0.6 (unreleased) ---------------- +- Fix issues populating correct link field when multiple rows are added. + [alecpm] + +- Fix title display when multiple rows reference the same UID. + [alecpm] + - Rename ``referencedatagridwidget.js`` to ``referencedatagridwidget.min.js`` and ``referencedatagridwidget.dev.js`` to ``referencedatagridwidget.js``. [thet] diff --git a/collective/referencedatagridfield/_field.py b/collective/referencedatagridfield/_field.py index f292910..5222350 100644 --- a/collective/referencedatagridfield/_field.py +++ b/collective/referencedatagridfield/_field.py @@ -157,8 +157,10 @@ def get(self, instance, **kwargs): # Process UIDs if uids: brains = catalog(UID=uids.keys()) - for b in brains: - data = uids[b.UID] + brain_map = dict((b.UID, b) for b in brains) + for data in result: + uid = data.get('uid') + b = brain_map.get(uid) data["url"] = b.getURL() data["link"] = b.getPath() data["default_title"] = self._brains_title_or_id(b, instance) diff --git a/collective/referencedatagridfield/skins/referencedatagridfield/referencedatagridwidget.js b/collective/referencedatagridfield/skins/referencedatagridfield/referencedatagridwidget.js index 3003ddd..4d9ba2f 100644 --- a/collective/referencedatagridfield/skins/referencedatagridfield/referencedatagridwidget.js +++ b/collective/referencedatagridfield/skins/referencedatagridfield/referencedatagridwidget.js @@ -8,8 +8,8 @@ if (dataGridFieldFunctions === undefined) { (function(jq) { + var active_tr; /* UTILITIES */ - function showMessageRDG(message) { jq('#messageTitle').text(message); jq('#message').show(); @@ -280,6 +280,7 @@ if (dataGridFieldFunctions === undefined) { ov.close(); } wrap = this.getOverlay().find('.overlaycontent'); + active_tr = this.getTrigger().parents('tr#datagridwidget-row'); src = this.getTrigger().prop('src'); srcfilter = src + ' >*'; wrap.data('srcfilter', srcfilter); @@ -314,7 +315,7 @@ if (dataGridFieldFunctions === undefined) { // the links for inserting referencens jq(document).on('click', '[id^=atdgrb_] input.insertreferencedatagrid', function () { - var target, wrap, fieldname, fieldtitle, fieldlink, multi, close_window, title, linkpath, active_tr, uid, overlay; + var target, wrap, fieldname, fieldtitle, fieldlink, multi, close_window, title, linkpath, uid, overlay; target = jq(this); wrap = target.parents('.overlaycontent'); fieldname = wrap.find('input[name=fieldName]').prop('value'); @@ -325,7 +326,6 @@ if (dataGridFieldFunctions === undefined) { //var title = target.parents('tr').find('img').prop('alt'); title = target.parent().next('td').find('strong').html(); linkpath = target.next('input').attr('rel'); - active_tr = wrap.parents('tr[id=datagridwidget-row]'); uid = target.attr('rel'); refdatagridbrowser_setReference(fieldname, uid, title, parseInt(multi, 10), active_tr, fieldtitle, title, fieldlink, linkpath); @@ -428,6 +428,18 @@ if (dataGridFieldFunctions === undefined) { return value; } + function update_add_src(row) { + var add_src = row.find('.addreferencedatagrid').attr('src'); + var inputs = row.find('input'); + jq('#datagridwidget-empty-row input').each(function (i, e) { + var old_id = jq(e).attr('id'); + var new_id = jq(inputs[i]).attr('id'); + if (old_id && new_id) { + add_src = add_src.replace(old_id, new_id); + } + }); + row.find('.addreferencedatagrid').attr('src', add_src); + } // ReferenceDataGridField related functions dataGridFieldFunctions.addReferenceDataGridRow = function (id) { @@ -442,9 +454,11 @@ if (dataGridFieldFunctions === undefined) { // Add row with own DataGridField method this.addRow(id); - // Find active row and add overlay related processors for active row + // Find active row, update overlay target and add overlay related + // processors for active row var active_row = jq("#datagridwidget-tbody-" + id + " tr#datagridwidget-row:last"); - jq(active_row).prepRefPopup(); + update_add_src(active_row); + active_row.prepRefPopup(); }; dataGridFieldFunctions.addReferenceDataGridRowAfter = function (currnode) { @@ -458,11 +472,12 @@ if (dataGridFieldFunctions === undefined) { // find active row var tbody, rows, curr_row, active_row; tbody = jq(currnode).parents("[id^=datagridwidget-tbody-]"); - rows = jq("#datagridwidget-row", tbody); + rows = jq("tr#datagridwidget-row", tbody); curr_row = jq(currnode).parents("tr#datagridwidget-row"); - active_row = rows[rows.index(curr_row) - 1]; + active_row = jq(rows[rows.index(curr_row) - 1]); + update_add_src(active_row); // add overlay related processors for active row - jq(active_row).prepRefPopup(); + active_row.prepRefPopup(); }; dataGridFieldFunctions.OriginalUpdateOrderIndex = dataGridFieldFunctions.updateOrderIndex; @@ -472,7 +487,7 @@ if (dataGridFieldFunctions === undefined) { this.OriginalUpdateOrderIndex(tbody); // Update overlay related attributes after rows index updating // for all datagridwidget rows - rows = jq("#datagridwidget-row", tbody); + rows = jq("tr#datagridwidget-row", tbody); for (i = 0; i < rows.length; i = i + 1) { // get working row tr = rows[i]; diff --git a/collective/referencedatagridfield/skins/referencedatagridfield/referencedatagridwidget.min.js b/collective/referencedatagridfield/skins/referencedatagridfield/referencedatagridwidget.min.js index 3122040..c3fa751 100644 --- a/collective/referencedatagridfield/skins/referencedatagridfield/referencedatagridwidget.min.js +++ b/collective/referencedatagridfield/skins/referencedatagridfield/referencedatagridwidget.min.js @@ -1,25 +1 @@ -if(void 0===dataGridFieldFunctions)var dataGridFieldFunctions={} -!function(e){function t(t){e("#messageTitle").text(t),e("#message").show()}function n(t){e("ul#"+t+" :input").each(function(){var t,n -t=e(this).prop("value"),n=e("input[rel="+t+"]"),n.prop("disabled",!0),n.prop("checked",!0)})}function a(){e(document).data("atdgrb_history",[])}function i(t){var n=e(document).data("atdgrb_history") -n.push(t),e(document).data("atdgrb_history",n)}function r(t,a,i){var r=e("[id^=atdgrb_] form#history select") -t.load(a,function(){var t,a -e("[id^=atdgrb_] form#history select").append(i+r.html()),t=e("div#content").data("overlay"),a=t.getTrigger().attr("rel").substring(6),n(a)})}function d(t){var n,a,i -n=e(t.target),a=n.prop("value"),i=n.prop("default_value"),null!==i&&null!==a&&(i===a?n.prop("class","not-changed-title-field"):n.prop("class","changed-title-field"))}function l(t){e(t.target).prop("class","changed-title-field")}function o(e){var t=e.parentNode,n=null,a=null,i=null,r=null,d=null,l=null,p=null -return null===t?!1:(n=t.id.split("-"),a=n.pop(),0===a?!1:(i=n.pop(),r=t.cloneNode(!0),p=r.getElementsByTagName("input"),p.length>0&&(p[0].checked=t.getElementsByTagName("input")[0].checked),d=document.getElementById("ref-"+i+"-"+(a-1)),l=r.getElementsByTagName("a"),l[0].onclick=function(){o(this)},l[1].onclick=function(){u(this)},t.parentNode.insertBefore(r,d),t.parentNode.removeChild(t),r.id="ref-"+i+"-"+(a-1),void(d.id="ref-"+i+"-"+a)))}function u(t){var n=t.parentNode,a=null,i=null,r=null,d=null,l=null,p=null,c=null,s=null -return null===n?!1:(a=n.id.split("-"),i=parseInt(a.pop(),10),r=a.pop(),d=e("#"+r+" input"),i+1===d.length?!1:(l=n.cloneNode(!0),c=l.getElementsByTagName("input"),c.length>0&&(c[0].checked=n.getElementsByTagName("input")[0].checked),s=l.getElementsByTagName("a"),s[0].onclick=function(){o(this)},s[1].onclick=function(){u(this)},p=document.getElementById("ref-"+r+"-"+(i+1)),n.parentNode.insertBefore(l,p.nextSibling),n.parentNode.removeChild(n),l.id="ref-"+r+"-"+(i+1),void(p.id="ref-"+r+"-"+i)))}function p(t,n,a,i,r,p,c,s,f){var m,g,v,h,y=null,b=null,N=null,w=null,_=null,k=null,T=null,x=null -if(void 0!==r&&void 0!==c&&void 0!==f&&void 0!==p&&void 0!==s)e("#"+t,r).prop("value",n),m=e("#"+p,r),m.prop("value",c),m.addClass("not-changed-title-field"),m.prop("default_value",c),m.blur(d),m.focus(l),g=e("#"+s,r),g.prop("readonly",!1),g.prop("value",f),g.prop("readonly",!0),g.addClass("hidden-field") -else if(0===i)e("#"+t).prop("value",n),e("#"+t+"_label").prop("value",a) -else{for(b=e("#"+t+" input"),v=0;v'),N=document.getElementById(t)),w=document.createElement("li"),y=document.createElement("label"),_=document.createElement("input"),_.type="checkbox",_.value=n,_.checked=!0,_.name=t+":list",y.appendChild(_),y.appendChild(document.createTextNode(" "+a)),w.appendChild(y),w.id="ref-"+t+"-"+b.length,h=e("input[name="+t+"-sortable]").prop("value"),"1"===h&&(k=document.createElement("a"),k.title="Move Up",k.innerHTML="▲",k.onclick=function(){return o(this),!1},w.appendChild(k),T=document.createElement("a"),T.title="Move Down",T.innerHTML="▼",T.onclick=function(){return u(this),!1},w.appendChild(T)),N.appendChild(w),console.log(N),console.log(w),_.checked=!0}}function c(d){e(function(){e(".addreferencedatagrid",d).overlay({closeOnClick:!1,onBeforeLoad:function(){var t,n,i,r -t=e("div#content").data("overlay"),t&&t.close(),n=this.getOverlay().find(".overlaycontent"),i=this.getTrigger().prop("src"),r=i+" >*",n.data("srcfilter",r),e("div#content").data("overlay",this),a(),n.load(r)},onLoad:function(){var e=this.getTrigger().attr("rel").substring(6) -n(e)}}),e(document).on("click","[id^=atdgrb_] a.browsesite",function(){var t,n,a,d,l -return t=e(this),n=t.prop("href"),a=t.parents(".overlaycontent"),d=n+" >*",i(a.data("srcfilter")),a.data("srcfilter",d),l='",r(a,d,l),!1}),e(document).on("click","[id^=atdgrb_] input.insertreferencedatagrid",function(){var n,a,i,r,d,l,o,u,c,s,f,m -n=e(this),a=n.parents(".overlaycontent"),i=a.find("input[name=fieldName]").prop("value"),r=a.find("input[name=fieldTitleName]").prop("value"),d=a.find("input[name=fieldLinkName]").prop("value"),l=a.find("input[name=multiValued]").prop("value"),o=a.find("input[name=close_window]").prop("value"),u=n.parent().next("td").find("strong").html(),c=n.next("input").attr("rel"),s=a.parents("tr[id=datagridwidget-row]"),f=n.attr("rel"),p(i,f,u,parseInt(l,10),s,r,u,d,c),"1"===o?(m=e("div#content").data("overlay"),m.close()):t(u),e(this).prop("disabled",!0)}),e(document).on("change","[id^=atdgrb_] form#history select[name=path]",function(){var t,n,a,i -return t=e(this),n=t.parents(".overlaycontent"),a=e("[id^=atdgrb_] form#history select[name=path] :selected",this).prop("value"),i=a+" >*",r(n,i,""),!1}),e(document).on("click","[id^=atdgrb_] div.listingBar a",function(){var t,n,a,i -return t=e(this),a=t.prop("href"),n=t.parents(".overlaycontent"),i=a+" >*",r(n,i,""),!1}),e(document).on("click","[id^=atdgrb_] form#search input[name=submit]",function(){var t,n,a,d,l,o,u,p,c,s,f,m,g -return t=e(this),n=t.parents("form").prop("action"),a=t.parents(".overlaycontent"),d=a.find("input[name=fieldName]").prop("value"),l=a.find("input[name=fieldTitleName]").prop("value"),o=a.find("input[name=fieldLinkName]").prop("value"),u=a.find("input[name=fieldRealName]").prop("value"),p=a.find("input[name=at_url]").prop("value"),c=a.find("input[name=searchValue]").prop("value"),s=a.find("input[name=multiValued]").prop("value"),f=a.find("input[name=close_window]").prop("value"),m="searchValue="+c+"&fieldRealName="+u+"&fieldName="+d+"&multiValued="+s+"&close_window="+f+"&at_url="+p+"&fieldTitleName="+l+"&fieldLinkName="+o,g=n+"?"+m+" >*",i(a.data("srcfilter")),a.data("srcfilter",g),r(a,g,""),!1})})}e(document).ready(function(){c(this)}),e.fn.prepRefPopup=function(){c(this)},dataGridFieldFunctions.addReferenceDataGridRow=function(t){this.addRow(t) -var n=e("#datagridwidget-tbody-"+t+" tr#datagridwidget-row:last") -e(n).prepRefPopup()},dataGridFieldFunctions.addReferenceDataGridRowAfter=function(t){this.addRowAfter(t) -var n,a,i,r -n=e(t).parents("[id^=datagridwidget-tbody-]"),a=e("#datagridwidget-row",n),i=e(t).parents("tr#datagridwidget-row"),r=a[a.index(i)-1],e(r).prepRefPopup()},dataGridFieldFunctions.OriginalUpdateOrderIndex=dataGridFieldFunctions.updateOrderIndex,dataGridFieldFunctions.updateOrderIndex=function(t){var n,a,i,r,d,l,o,u,p,c -for(this.OriginalUpdateOrderIndex(t),n=e("#datagridwidget-row",t),u=0;u=0?d.substring(0,l):"#atrb",o=c+"_"+i,r.attr("rel",o),e("div[id^=atdgrb_]",a).prop("id",o.substring(1))}}(jQuery) +if(void 0===dataGridFieldFunctions)var dataGridFieldFunctions={};!function(e){function t(t){e("#messageTitle").text(t),e("#message").show()}function n(t){e("ul#"+t+" :input").each(function(){var t,n;t=e(this).prop("value"),n=e("input[rel="+t+"]"),n.prop("disabled",!0),n.prop("checked",!0)})}function a(){e(document).data("atdgrb_history",[])}function i(t){var n=e(document).data("atdgrb_history");n.push(t),e(document).data("atdgrb_history",n)}function r(t,a,i){var r=e("[id^=atdgrb_] form#history select");t.load(a,function(){var t,a;e("[id^=atdgrb_] form#history select").append(i+r.html()),t=e("div#content").data("overlay"),a=t.getTrigger().attr("rel").substring(6),n(a)})}function d(t){var n,a,i;n=e(t.target),a=n.prop("value"),i=n.prop("default_value"),null!==i&&null!==a&&(i===a?n.prop("class","not-changed-title-field"):n.prop("class","changed-title-field"))}function l(t){e(t.target).prop("class","changed-title-field")}function o(e){var t=e.parentNode,n=null,a=null,i=null,r=null,d=null,l=null,p=null;return null===t?!1:(n=t.id.split("-"),a=n.pop(),0===a?!1:(i=n.pop(),r=t.cloneNode(!0),p=r.getElementsByTagName("input"),p.length>0&&(p[0].checked=t.getElementsByTagName("input")[0].checked),d=document.getElementById("ref-"+i+"-"+(a-1)),l=r.getElementsByTagName("a"),l[0].onclick=function(){o(this)},l[1].onclick=function(){u(this)},t.parentNode.insertBefore(r,d),t.parentNode.removeChild(t),r.id="ref-"+i+"-"+(a-1),void(d.id="ref-"+i+"-"+a)))}function u(t){var n=t.parentNode,a=null,i=null,r=null,d=null,l=null,p=null,c=null,s=null;return null===n?!1:(a=n.id.split("-"),i=parseInt(a.pop(),10),r=a.pop(),d=e("#"+r+" input"),i+1===d.length?!1:(l=n.cloneNode(!0),c=l.getElementsByTagName("input"),c.length>0&&(c[0].checked=n.getElementsByTagName("input")[0].checked),s=l.getElementsByTagName("a"),s[0].onclick=function(){o(this)},s[1].onclick=function(){u(this)},p=document.getElementById("ref-"+r+"-"+(i+1)),n.parentNode.insertBefore(l,p.nextSibling),n.parentNode.removeChild(n),l.id="ref-"+r+"-"+(i+1),void(p.id="ref-"+r+"-"+i)))}function p(t,n,a,i,r,p,c,s,f){var g,m,v,h,y=null,b=null,w=null,N=null,_=null,k=null,T=null,x=null;if(void 0!==r&&void 0!==c&&void 0!==f&&void 0!==p&&void 0!==s)e("#"+t,r).prop("value",n),g=e("#"+p,r),g.prop("value",c),g.addClass("not-changed-title-field"),g.prop("default_value",c),g.blur(d),g.focus(l),m=e("#"+s,r),m.prop("readonly",!1),m.prop("value",f),m.prop("readonly",!0),m.addClass("hidden-field");else if(0===i)e("#"+t).prop("value",n),e("#"+t+"_label").prop("value",a);else{for(b=e("#"+t+" input"),v=0;v'),w=document.getElementById(t)),N=document.createElement("li"),y=document.createElement("label"),_=document.createElement("input"),_.type="checkbox",_.value=n,_.checked=!0,_.name=t+":list",y.appendChild(_),y.appendChild(document.createTextNode(" "+a)),N.appendChild(y),N.id="ref-"+t+"-"+b.length,h=e("input[name="+t+"-sortable]").prop("value"),"1"===h&&(k=document.createElement("a"),k.title="Move Up",k.innerHTML="▲",k.onclick=function(){return o(this),!1},N.appendChild(k),T=document.createElement("a"),T.title="Move Down",T.innerHTML="▼",T.onclick=function(){return u(this),!1},N.appendChild(T)),w.appendChild(N),console.log(w),console.log(N),_.checked=!0}}function c(d){e(function(){e(".addreferencedatagrid",d).overlay({closeOnClick:!1,onBeforeLoad:function(){var t,n,i,r;t=e("div#content").data("overlay"),t&&t.close(),n=this.getOverlay().find(".overlaycontent"),f=this.getTrigger().parents("tr#datagridwidget-row"),i=this.getTrigger().prop("src"),r=i+" >*",n.data("srcfilter",r),e("div#content").data("overlay",this),a(),n.load(r)},onLoad:function(){var e=this.getTrigger().attr("rel").substring(6);n(e)}}),e(document).on("click","[id^=atdgrb_] a.browsesite",function(){var t,n,a,d,l;return t=e(this),n=t.prop("href"),a=t.parents(".overlaycontent"),d=n+" >*",i(a.data("srcfilter")),a.data("srcfilter",d),l='",r(a,d,l),!1}),e(document).on("click","[id^=atdgrb_] input.insertreferencedatagrid",function(){var n,a,i,r,d,l,o,u,c,s,g;n=e(this),a=n.parents(".overlaycontent"),i=a.find("input[name=fieldName]").prop("value"),r=a.find("input[name=fieldTitleName]").prop("value"),d=a.find("input[name=fieldLinkName]").prop("value"),l=a.find("input[name=multiValued]").prop("value"),o=a.find("input[name=close_window]").prop("value"),u=n.parent().next("td").find("strong").html(),c=n.next("input").attr("rel"),s=n.attr("rel"),p(i,s,u,parseInt(l,10),f,r,u,d,c),"1"===o?(g=e("div#content").data("overlay"),g.close()):t(u),e(this).prop("disabled",!0)}),e(document).on("change","[id^=atdgrb_] form#history select[name=path]",function(){var t,n,a,i;return t=e(this),n=t.parents(".overlaycontent"),a=e("[id^=atdgrb_] form#history select[name=path] :selected",this).prop("value"),i=a+" >*",r(n,i,""),!1}),e(document).on("click","[id^=atdgrb_] div.listingBar a",function(){var t,n,a,i;return t=e(this),a=t.prop("href"),n=t.parents(".overlaycontent"),i=a+" >*",r(n,i,""),!1}),e(document).on("click","[id^=atdgrb_] form#search input[name=submit]",function(){var t,n,a,d,l,o,u,p,c,s,f,g,m;return t=e(this),n=t.parents("form").prop("action"),a=t.parents(".overlaycontent"),d=a.find("input[name=fieldName]").prop("value"),l=a.find("input[name=fieldTitleName]").prop("value"),o=a.find("input[name=fieldLinkName]").prop("value"),u=a.find("input[name=fieldRealName]").prop("value"),p=a.find("input[name=at_url]").prop("value"),c=a.find("input[name=searchValue]").prop("value"),s=a.find("input[name=multiValued]").prop("value"),f=a.find("input[name=close_window]").prop("value"),g="searchValue="+c+"&fieldRealName="+u+"&fieldName="+d+"&multiValued="+s+"&close_window="+f+"&at_url="+p+"&fieldTitleName="+l+"&fieldLinkName="+o,m=n+"?"+g+" >*",i(a.data("srcfilter")),a.data("srcfilter",m),r(a,m,""),!1})})}function s(t){var n=t.find(".addreferencedatagrid").attr("src"),a=t.find("input");e("#datagridwidget-empty-row input").each(function(t,i){var r=e(i).attr("id"),d=e(a[t]).attr("id");r&&d&&(n=n.replace(r,d))}),t.find(".addreferencedatagrid").attr("src",n)}var f;e(document).ready(function(){c(this)}),e.fn.prepRefPopup=function(){c(this)},dataGridFieldFunctions.addReferenceDataGridRow=function(t){this.addRow(t);var n=e("#datagridwidget-tbody-"+t+" tr#datagridwidget-row:last");s(n),n.prepRefPopup()},dataGridFieldFunctions.addReferenceDataGridRowAfter=function(t){this.addRowAfter(t);var n,a,i,r;n=e(t).parents("[id^=datagridwidget-tbody-]"),a=e("tr#datagridwidget-row",n),i=e(t).parents("tr#datagridwidget-row"),r=e(a[a.index(i)-1]),s(r),r.prepRefPopup()},dataGridFieldFunctions.OriginalUpdateOrderIndex=dataGridFieldFunctions.updateOrderIndex,dataGridFieldFunctions.updateOrderIndex=function(t){var n,a,i,r,d,l,o,u,p,c;for(this.OriginalUpdateOrderIndex(t),n=e("tr#datagridwidget-row",t),u=0;u=0?d.substring(0,l):"#atrb",o=c+"_"+i,r.attr("rel",o),e("div[id^=atdgrb_]",a).prop("id",o.substring(1))}}(jQuery); \ No newline at end of file