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

ZMSRecordSet: multiple row inserting in grid-view #350

Open
wants to merge 2 commits into
base: main
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
2 changes: 1 addition & 1 deletion Products/zms/_multilangmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def manage_changeLangDictProperties(self, lang, btn, REQUEST, RESPONSE=None):
if enabled:
lang_dict[key][lang_id] = REQUEST['%s_value_%s'%(key, lang_id)].strip()
# Insert (multiple) new language keys at once.
# Ref: ZMSMetaobjManager.py#L1294
# Ref: ZMSMetaobjManager.py#L1207
for key in REQUEST.form.keys():
if key.startswith('_lang_dict_key_'):
i = int(key[len('_lang_dict_key_'):])
Expand Down
27 changes: 15 additions & 12 deletions Products/zms/zmscustom.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,9 @@ def handle_record(self, r):


############################################################################
# ZMSCustom.manage_changeRecordSet:
# ZMSCustom.manage_changeRecordGrid:
#
# Change record-set.
# Change record-grid.
############################################################################
def manage_changeRecordGrid(self, lang, btn, REQUEST, RESPONSE):
""" ZMSCustom.manage_changeRecordGrid """
Expand Down Expand Up @@ -525,14 +525,15 @@ def retrieve(row):
row['_change_dt'] = standard.getDateTime( time.time())
for metaObjAttr in filter_columns:
objAttr = self.getObjAttr(metaObjAttr['id'])
# Hint: objAttrName gets nested by REQUEST-vars objAttrNamePrefix, objAttrNameSuffix
objAttrName = self.getObjAttrName(objAttr, lang)
if metaObjAttr['type'] in self.metaobj_manager.valid_types or \
metaObjAttr['type'] not in self.metaobj_manager.valid_xtypes+self.metaobj_manager.valid_zopetypes:
set, value = True, self.formatObjAttrValue(objAttr, REQUEST.get(objAttrName), lang)
try: del value['aq_parent']
except: pass
if value is None and metaObjAttr['id'] == 'sort_id':
value = len(res_abs)
# if value is None and metaObjAttr['id'] == 'sort_id':
# value = len(res_abs) ### CAVE NameError: 'res_abs' not defined
if value is None and metaObjAttr['type'] in ['file', 'image'] and int(REQUEST.get('del_%s'%objAttrName, 0)) == 0:
set = False
if set:
Expand All @@ -548,18 +549,20 @@ def retrieve(row):
# Update
c = 0
for record in records:
REQUEST.set('objAttrNamePrefix', '');
REQUEST.set('objAttrNameSuffix', '_%i'%c);
REQUEST.set('objAttrNamePrefix', '')
REQUEST.set('objAttrNameSuffix', '_%i'%c)
record = retrieve(record)
if record is not None:
new_records.append(record)
c += 1
# Insert
REQUEST.set('objAttrNamePrefix', '_');
REQUEST.set('objAttrNameSuffix', '');
record = retrieve({})
if record is not None:
new_records.append(record)
# Insert new records: var names start with '_'
REQUEST.set('objAttrNamePrefix', '_')
REQUEST.set('objAttrNameSuffix', '')
for new_col_id_idx in [k[8:] for k in REQUEST.form.keys() if k.startswith('_col_id_')]:
REQUEST.set('objAttrNameSuffix', '_%s'%new_col_id_idx)
record = retrieve({})
if record is not None:
new_records.append(record)
message = self.getZMILangStr('MSG_CHANGED')
# Set
self.setObjProperty(record_id, new_records, lang)
Expand Down
124 changes: 63 additions & 61 deletions Products/zms/zpt/ZMSRecordSet/grid.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
</tr>
</tal:block>
</tal:block>
<tr class="new_row_insert" tal:condition="python:not num_rows or num_rows<0 or num_rows<len(records)">
<tr class="row_insert" tal:condition="python:not num_rows or num_rows<0 or num_rows<len(records)">
<td class="meta-sort zmi-datatype-action">
<input type="hidden" name="_col_id" id="_col_id" tal:attributes="value python:'e%i'%(records_len)" />
<input type="hidden" name="_sort_id" id="_sort_id" tal:attributes="value python:'%i'%(records_len + 1)" />
Expand Down Expand Up @@ -253,74 +253,76 @@
// Prepare multiple inserts
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// // New field set: initially disable inputs
// $('input, textarea, select','tr.row_insert').attr('disabled',true);
// New field set: initially disable inputs
$('input, textarea, select','tr.row_insert').attr('disabled',true);

// // ++++++++++++
// // Add rows to table #grid0 on button click
// // ++++++++++++
// let new_row_counter = $('#grid0 tbody tr').length - 2;
// ++++++++++++
// Add rows to table #grid0 on button click
// ++++++++++++
let new_row_counter = $('#grid0 tbody tr').length - 2;

// // Add click event function to add-buttons
// $(".row_insert .btn-add").click(function(){
// new_row_counter++;
// // New field set: clone with enabled inputs
// $('input, textarea, select','tr.row_insert').attr('disabled',false);
// Add click event function to add-buttons
$(".row_insert .btn-add").click(function(){
new_row_counter++;
// New field set: clone with enabled inputs
$('input, textarea, select','tr.row_insert').attr('disabled',false);

// // Where to insert the new row
// let $where_insert = $(this).closest('tr');
// Where to insert the new row
let $where_insert = $(this).closest('tr');

// // Set variables
// let new_row_name = `tr_${new_row_counter}`;
// let new_btn_html = `
// <span class="btn btn-secondary btn-sm mr-1 w-100"
// title="Revoke new data set"
// onclick="javascript:$(this).closest('tr').hide('slow',function(){$(this).closest('tr').remove()})">
// <i class="fas fa-undo-alt"></i>
// </span>
// `;
// Set variables
let new_row_name = `tr_${new_row_counter}`;
let new_btn_html = `
<span class="btn btn-secondary btn-sm mr-1 w-100"
title="Revoke new data set"
onclick="javascript:$(this).closest('tr').hide('slow',function(){$(this).closest('tr').remove()})">
<i class="fas fa-undo-alt"></i>
</span>
`;

// // Clone(true) to get a deep copy including select options
// let $new_row = $where_insert.clone(true);
// Clone(true) to get a deep copy including select options
let $new_row = $where_insert.clone(true);

// // Process table cells of the clone like "old" row
// $new_row.find('td').each(function() {
// $(this).find('input,select,textarea').each(function() {
// let tagname = $(this).prop('tagName');
// let defname = $(this).attr('name');
// let deftype = $(this).attr('type');
// debugger;
// let newname = $(this).attr('name').split('_').at(-1);
// let newval = $(this).val();
// newname = `${newname}_${new_row_counter}`
// newname = defname.includes(':') ? `${newname}:int` : newname;
// $(this).attr('name',newname);
// $(this).attr('id',newname);
// newval = `new${new_row_counter}`;
// if ( tagname == 'INPUT' && deftype != 'checkbox' && deftype != 'file' ) {
// $(this).val(newval);
// $(this).attr('placeholder',newval);
// } else if ( deftype == 'checkbox' ) {
// $(this).val(1);
// };
// });
// });
// Process table cells of the clone like "old" row
$new_row.find('td').each(function() {
$(this).find('input,select,textarea').each(function() {
let tagname = $(this).prop('tagName');
let defname = $(this).attr('name');
let deftype = $(this).attr('type');
debugger;
// let newname = $(this).attr('name').split('_').at(-1);
// newname = defname.includes(':') ? `${newname}:int` : newname;
let newname = `${defname}_${new_row_counter}`
let newval = $(this).val();
$(this).attr('name',newname);
$(this).attr('id',newname);
newval = `new_${new_row_counter}`;
if ( defname.startsWith('del_') ) {
$(this).val(0);
} else if ( tagname == 'INPUT' && deftype != 'checkbox' && deftype != 'file' ) {
$(this).val(newval);
$(this).attr('placeholder',newval);
} else if ( deftype == 'checkbox' ) {
$(this).val(1);
};
});
});

// // Process td:first-child of the clone
// $new_row.find('td.meta-sort').html(new_btn_html);
// $new_row.removeClass('row_insert').attr('id',new_row_name)
// Process td:first-child of the clone
$new_row.find('td.meta-sort span').replaceWith(new_btn_html);
$new_row.removeClass('row_insert').attr('id',new_row_name)

// // Insert the new row
// $new_row.insertBefore($where_insert);
// // Set form as modified
// $ZMI.set_form_modified($('.meta-id input',$new_row));
// // Reset the clone template
// $where_insert.find('input:not([type="checkbox"]),select,textarea').each(function() {
// $(this).val(undefined);
// });
// // New field set: reset to disabled inputs
// $('input, textarea, select','tr.row_insert').attr('disabled',true);
// });
// Insert the new row
$new_row.insertBefore($where_insert);
// Set form as modified
$ZMI.set_form_modified($('.meta-id input',$new_row));
// Reset the clone template
$where_insert.find('input:not([type="checkbox"]),select,textarea').each(function() {
$(this).val(undefined);
});
// New field set: reset to disabled inputs
$('input, textarea, select','tr.row_insert').attr('disabled',true);
});

});
//-->
Expand Down
Loading