Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues populating correct link field when multiple rows are added. #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 4 additions & 2 deletions collective/referencedatagridfield/_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ if (dataGridFieldFunctions === undefined) {

(function(jq) {

var active_tr;
/* UTILITIES */

function showMessageRDG(message) {
jq('#messageTitle').text(message);
jq('#message').show();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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];
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.