Skip to content

Commit

Permalink
Improved ZMSMetaobjManager GUI
Browse files Browse the repository at this point in the history
Intermediate saving on adding new attributes
to the content model  not necessary anymore
  • Loading branch information
drfho committed Jul 12, 2023
1 parent beefa09 commit 751c21a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 28 deletions.
16 changes: 15 additions & 1 deletion Products/zms/ZMSMetaobjManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<br/>'%(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<br/>'%(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion Products/zms/plugins/www/zmi.core.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
101 changes: 76 additions & 25 deletions Products/zms/zpt/ZMSMetamodelProvider/manage_main.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
</tal:block>
</tr>
<tr class="row_insert">
<td class="meta-sort text-right"><span class="btn btn-add"><i class="fas fa-plus')"></i></span></td>
<td class="meta-sort text-right"><span class="btn btn-add mr-1"><i class="fas fa-plus"></i></span></td>
<td class="meta-id"><input class="form-control form-control-sm" type="text" name="attr_id"/></td>
<td class="meta-name"><input class="form-control form-control-sm" type="text" name="attr_name"/></td>
<td class="meta-type">
Expand Down Expand Up @@ -357,31 +357,32 @@
<!-- EO Usage -->

<!-- BO Languages -->
<div class="meta-languages mt-3" tal:define="langIds python:here.getLangIds(sort=True)">
<table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th tal:content="python:here.getZMILangStr('ATTR_DICTIONARY')"></th>
<th tal:content="python:here.getZMILangStr('ATTR_KEY')">Key</th>
<th tal:repeat="langId langIds" tal:content="python:here.getLanguageLabel(langId)">Language-Label</th>
</tr>
</thead>
<tbody>
<tal:block tal:repeat="langDict python:here.getLangDict()">
<tr tal:condition="python:langDict['key'].startswith(request['id'])" tal:define="i python:repeat['langDict'].index+1">
<td class="text-center"></td>
<td><input type="text" class="form-control form-control-sm" tal:attributes="name python:'_lang_dict_key_%i'%i; value python:langDict['key'][len(request['id'])+1:];"></td>
<td tal:repeat="langId langIds"><div class="single-line"><textarea class="form-control form-control-sm" tal:attributes="name python:'_lang_dict_value_%i_%s'%(i,langId);" tal:content="python:langDict.get(langId,'')"></textarea></div></td>
</tr>
</tal:block>
<tr class="row_insert" tal:define="i python:0">
<td class="text-center"><i class="fas fa-plus"></i></td>
<td><input class="form-control form-control-sm" type="text" tal:attributes="name python:'_lang_dict_key_%i'%i" /></td>
<td tal:repeat="langId langIds"><div class="single-line"><textarea class="form-control form-control-sm" tal:attributes="name python:'_lang_dict_value_%i_%s'%(i,langId)"></textarea></div></td>
</tr>
</tbody>
<table id="meta_languages"
tal:define="langIds python:here.getLangIds(sort=True)"
class="table table-sm table-striped table-bordered table-hover mt-3">
<thead>
<tr>
<th class="meta-sort"></th>
<th tal:content="python:'%s - %s'%(here.getZMILangStr('ATTR_DICTIONARY'), here.getZMILangStr('ATTR_KEY'))">Key</th>
<th tal:repeat="langId langIds" tal:content="python:here.getLanguageLabel(langId)">Language-Label</th>
</tr>
</thead>
<tbody>
<tal:block tal:repeat="langDict python:here.getLangDict()">
<tr tal:condition="python:langDict['key'].startswith(request['id'])" tal:define="i python:repeat['langDict'].index+1">
<td class="meta-sort"></td>
<td><input type="text" class="form-control form-control-sm" tal:attributes="name python:'_lang_dict_key_%i'%i; value python:langDict['key'][len(request['id'])+1:];"></td>
<td tal:repeat="langId langIds"><div class="single-line"><textarea class="form-control form-control-sm" tal:attributes="name python:'_lang_dict_value_%i_%s'%(i,langId);" tal:content="python:langDict.get(langId,'')"></textarea></div></td>
</tr>
</tal:block>
<tr class="row_insert" tal:define="i python:0">
<td class="meta-sort text-right"><span class="btn btn-add mr-1"><i class="fas fa-plus"></i></span></td>
<td><input class="form-control form-control-sm" type="text" tal:attributes="name python:'_lang_dict_key_%i'%i" /></td>
<td tal:repeat="langId langIds"><div class="single-line"><textarea class="form-control form-control-sm" tal:attributes="name python:'_lang_dict_value_%i_%s'%(i,langId)"></textarea></div></td>
</tr>
</tbody>
</table>
</div>
<!-- EO Languages -->

<!-- BO Access -->
<div class="meta-access">
Expand Down Expand Up @@ -793,6 +794,56 @@ $(function(){
var zmi_code_default_btn = '<i onclick="set_zmi_code_default(event)" title=\"Replace by Default-Code-Template\" class=\"zmi-code-default icon-repeat fas fa-redo-alt text-primary text-center\" style=\"cursor:pointer;display:block;position:absolute;text-align:right !important;right:0.75em;padding:0.5em;\"></i>';
$(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('<input type="hidden" name="old_ids:list" value="new'+ new_row_counter +'"><span style="color:#999" class="btn btn-default btn-sm mr-1" onclick="javascript:$(this).closest(\'tr\').remove()"><i class="fas fa-times"></i></span>');
$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);
});

});
// -->
</script>
Expand Down

0 comments on commit 751c21a

Please sign in to comment.