Skip to content

Commit

Permalink
using js-switch() for case handling
Browse files Browse the repository at this point in the history
  • Loading branch information
drfho committed Jul 13, 2023
1 parent ce885f6 commit dc676e0
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions Products/zms/zpt/ZMSMetamodelProvider/manage_main.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -831,34 +831,41 @@ $(function(){
let tagname = $(this).prop('tagName');
let newname = $(this).attr('name').split('_')[1];

// Set new form elemnt names
if (table_id=='meta_properties') {
switch (newname.includes(':')) {
case true: // Checkboxes (:int-suffix)
$(this).attr('name', `attr_${newname.split(':')[0]}_new${new_row_counter}:${newname.split(':')[1]}`);
break;
default: // String Inputs
$(this).attr('name', `attr_${newname}_new${new_row_counter}`);
}
} else if (table_id=='meta_languages') {
$(this).attr('name',$(this).attr('name').replace('_0', '_' + (lang_count + new_row_counter)));
};
// Transfer values to clone
if ( ['TEXTAREA', 'INPUT'].includes(tagname) ) {
if (newname.includes(':')) {
// Checkboxes (:int-suffix)
$(this).val($(this).val()=='1' ? 1 : 0 );
} else {
// String Inputs
// #### NAMES: Set new form elemnt names according to table_id
switch (table_id) {
case 'meta_properties':
console.log(newname.includes(':'));
console.log(newname.split(':')[0]);
switch (newname.includes(':')) {
case true: // Checkboxes (:int-suffix)
$(this).attr('name', `attr_${newname.split(':')[0]}_new${new_row_counter}:${newname.split(':')[1]}`);
break
default: // String Inputs
$(this).attr('name', `attr_${newname}_new${new_row_counter}`);
};
case 'meta_languages':
$(this).attr('name',$(this).attr('name').replace('_0', '_' + (lang_count + new_row_counter)));
}

// #### VALUES: Transfer values from template to clone according to tag-name
switch (tagname) {
case 'INPUT':
switch (newname.includes(':')) {
case true: // Checkboxes (:int-suffix)
$(this).val($(this).val()=='1' ? 1 : 0 );
break
default: // String Inputs
$(this).val($(this).val()=='' ? ('new'+new_row_counter) : $(this).val());
};
case 'SELECT':
let selected = $("option:selected", $('.row_insert select')).val();
if (selected!='') {
$('option[value="' + selected +'"]',$(this)).prop('selected', true);
};
case 'TEXTAREA':
$(this).val($(this).val()=='' ? ('new'+new_row_counter) : $(this).val());
};
} else if ( tagname == 'SELECT' ) {
let selected = $("option:selected", $('.row_insert select')).val();
if (selected!='') {
$('option[value="' + selected +'"]',$(this)).prop('selected', true);
}
}
})
});
});

// Process td:first-child
Expand Down

0 comments on commit dc676e0

Please sign in to comment.