From 751c21a52b6dd3dc410f72c3c497b33c6c5562c3 Mon Sep 17 00:00:00 2001 From: drfho Date: Wed, 12 Jul 2023 16:36:16 +0200 Subject: [PATCH] Improved ZMSMetaobjManager GUI Intermediate saving on adding new attributes to the content model not necessary anymore --- Products/zms/ZMSMetaobjManager.py | 16 ++- .../bootstrap/plugin/bootstrap.plugin.zmi.js | 2 +- Products/zms/plugins/www/zmi.core.css | 1 - .../zpt/ZMSMetamodelProvider/manage_main.zpt | 101 +++++++++++++----- 4 files changed, 92 insertions(+), 28 deletions(-) diff --git a/Products/zms/ZMSMetaobjManager.py b/Products/zms/ZMSMetaobjManager.py index 11f84b761..d2ddb4ba8 100644 --- a/Products/zms/ZMSMetaobjManager.py +++ b/Products/zms/ZMSMetaobjManager.py @@ -1142,7 +1142,21 @@ def manage_changeProperties(self, lang, btn='', key='all', REQUEST=None, RESPONS self.setMetaobj( newValue) # Change attributes. for old_id in REQUEST.get('old_ids', []): - attr_id = REQUEST['attr_id_%s'%old_id].strip() + + try: + attr_id = REQUEST['attr_id_%s'%old_id].strip() + except: + if type(REQUEST.get('attr_id_%s'%old_id))==list: + # Error: doubled attribute ids + standard.writeLog(self, "[ZMSMetaobjManager.manage_changeProperties Doubled Attribute IDs]: %s"%(REQUEST.get('old_ids', []))) + message+='IGNORED Doubled ID: attr_id_%s
'%(old_id) + attr_id = REQUEST['attr_id_%s'%old_id][0].strip() + continue + else: + standard.writeLog(self, "[ZMSMetaobjManager.manage_changeProperties Key Error]: attr_id_%s"%(old_id)) + message+='IGNORED Key: attr_id_%s
'%(old_id) + continue + newName = REQUEST.get('attr_name_%s'%old_id, '').strip() newMandatory = REQUEST.get( 'attr_mandatory_%s'%old_id, 0) newMultilang = REQUEST.get( 'attr_multilang_%s'%old_id, 0) diff --git a/Products/zms/plugins/www/bootstrap/plugin/bootstrap.plugin.zmi.js b/Products/zms/plugins/www/bootstrap/plugin/bootstrap.plugin.zmi.js index 5e049e906..b0ec13c21 100644 --- a/Products/zms/plugins/www/bootstrap/plugin/bootstrap.plugin.zmi.js +++ b/Products/zms/plugins/www/bootstrap/plugin/bootstrap.plugin.zmi.js @@ -357,7 +357,7 @@ $ZMI.registerReady(function(){ } }); - // Double-Clickable + // Double-Clickable (TODO: to be specified for data grids that lead row-wise to a dataset form!) $('table.table-hover tbody tr') .dblclick( function(evt) { var href = null; diff --git a/Products/zms/plugins/www/zmi.core.css b/Products/zms/plugins/www/zmi.core.css index 0b029da04..72e2786d7 100644 --- a/Products/zms/plugins/www/zmi.core.css +++ b/Products/zms/plugins/www/zmi.core.css @@ -988,7 +988,6 @@ li.zmi-item span.zmi-ids { .zmi table.table td.meta-sort .btn.btn-secondary i.fas.fa-times, .zmi table.table td.meta-default .btn.btn-secondary i.fas.fa-key, .zmi table.table td.meta-default .btn.btn-secondary i.fas.fa-ellipsis-v, -.zmi .meta-languages .single-line.input-group i.fas, .zmi table.table .single-line.input-group .input-group-append i.fas { color: #999; } diff --git a/Products/zms/zpt/ZMSMetamodelProvider/manage_main.zpt b/Products/zms/zpt/ZMSMetamodelProvider/manage_main.zpt index f48c04781..3a4c961cc 100644 --- a/Products/zms/zpt/ZMSMetamodelProvider/manage_main.zpt +++ b/Products/zms/zpt/ZMSMetamodelProvider/manage_main.zpt @@ -315,7 +315,7 @@ - + @@ -357,31 +357,32 @@ -
- - - - - - - - - - - - - - - - - - - - - - +
KeyLanguage-Label
+ + + + + + + + + + + + + + + + + + + + +
KeyLanguage-Label
-
+
@@ -793,6 +794,56 @@ $(function(){ var zmi_code_default_btn = ''; $(function(){ $('#meta_properties input[name="attr_type_standard_html"] ~ .zmi-code').prepend( zmi_code_default_btn); + + + // ++++++++++++ + // Add rows to tables #meta_properties or #meta_languages on button click + // ++++++++++++ + let new_row_counter = 0; + // Determine the number of language terms + let lang_count = Object.keys(JSON.parse(ZMI.prototype.getCachedValue('get_lang_dict'))).length + + // Add Event to Add-Buttons + $(".row_insert .btn-add").click(function(){ + new_row_counter++; + + // Where to insert the new row + let $where_insert = $(this).closest('tr'); + + // Determine the container table id #meta_properties or #meta_languages + let table_id = $(this).closest('table').attr('id'); + let new_name = `new_row_${table_id}_${new_row_counter}`; + + // Clone(true) to get a deep copy including select options + let $new_row = $where_insert.clone(true); + + // Prepare the clone to work as an "old" row + $new_row.removeAttr('class'); + $new_row.find('.btn-add').remove(); + $new_row.attr('id',new_name); + $new_row.find('td.meta-sort').html(''); + $new_row.find('input[name="attr_id"]').attr('name','attr_id_new'+new_row_counter) + if ( $new_row.find('input[name="attr_id_new'+ new_row_counter +'"]').val()=='' ) { + $new_row.find('input[name="attr_id_new'+ new_row_counter +'"]').val('new'+new_row_counter); + }; + $new_row.find('input[name="attr_name"]').attr('name','attr_name_new'+new_row_counter) + if ( $new_row.find('input[name="attr_name_new'+ new_row_counter +'"]').val()=='' ) { + $new_row.find('input[name="attr_name_new'+ new_row_counter +'"]').val('new'+new_row_counter); + }; + // TODO: selected option should be shown in the cloned row + $new_row.find('select[name="_type"]').attr('name','attr_type_new'+ new_row_counter); + $new_row.find('input[name="_mandatory:int"]').attr('name','attr_mandatory_new' + new_row_counter + ':int'); + $new_row.find('input[name="_multilang:int]').attr('name','attr_multilang_new' + new_row_counter + ':int'); + $new_row.find('input[name="_repetitive:int]').attr('name','attr_repetitive_new' + new_row_counter + ':int'); + $new_row.find('[name^="_lang_dict_"]').each(function(){ + let new_lang_dict_count = lang_count + new_row_counter; + $(this).attr('name',$(this).attr('name').replace('_0', '_' + new_lang_dict_count )); + }); + + // Insert the new row + $new_row.insertBefore($where_insert); + }); + }); // -->