Skip to content

Commit

Permalink
handle form-modified in admin-zmi
Browse files Browse the repository at this point in the history
added specific form-group classes for containing form-modified class; more btn-save as secondary; row_insert triggers as form-modified
  • Loading branch information
drfho committed Sep 26, 2024
1 parent aa8c341 commit a51dfff
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 38 deletions.
27 changes: 9 additions & 18 deletions Products/zms/zpt/ZMS/manage_customizelanguagesform.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<tal:block tal:condition="not:python:si['parent'] in langStack and not langStack[-1]==si['parent']">
<tal:block tal:define="dummy python:langStack.append(si['parent'])"></tal:block>
</tal:block>
<tr tal:attributes="id python:'lang%s'%'_'.join(langStack+[langId])">
<tr tal:attributes="id python:'lang%s'%'_'.join(langStack+[langId])" class="form-group">
<td class="meta-sort text-center">
<div class="btn-group" tal:condition="python:langId!=here.getPrimaryLanguage()">
<span class="btn btn-secondary btn-sm">
Expand Down Expand Up @@ -77,7 +77,7 @@
</tal:block>
</tal:block>
</tal:block>
<tr class="row_insert">
<tr class="row_insert form-group">
<td class="meta-sort text-center"><span class="btn btn-secondary btn-sm btn-add mr-1 w-100"><i class="fas fa-plus"></i></span></td>
<td class="language_id"><input class="form-control form-control-sm" placeholder="ISO-639/2" minlength="2" maxlength="3" required="true" type="text" name="_lang_id_0" /></td>
<td class="language_label"><input class="form-control form-control-sm" required="true"type="text" name="_lang_label_0" /></td>
Expand All @@ -95,7 +95,7 @@
</tbody>
</table>
<div class="controls save">
<button title="Save Language Definitions" name="btn" type="submit" class="btn btn-primary" value="BTN_SAVE" tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</button>
<button title="Save Language Definitions" name="btn" type="submit" class="btn btn-secondary" value="BTN_SAVE" tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</button>
<button title="Delete Selected Language Definitions" name="btn" type="submit" class="btn btn-secondary" value="BTN_DELETE" tal:content="python:here.getZMILangStr('BTN_DELETE')">Delete</button>
</div>
</form>
Expand Down Expand Up @@ -135,7 +135,7 @@
</thead>
<tbody hx-confirm="Are you sure?" hx-target="closest tr" hx-swap="outerHTML swap:1s"
tal:attributes="hx-confirm python:here.getZMILangStr('MSG_CONFIRM_DELOBJ')">
<tr tal:repeat="langDict python:here.getLangDict()"
<tr tal:repeat="langDict python:here.getLangDict()" class="form-group"
tal:attributes="id python:'langkey_%s'%(langDict['key'])">
<td class="meta-sort text-center">
<div class="btn-group">
Expand All @@ -159,15 +159,15 @@
<td tal:attributes="title python:'getLangStr(\'%s\',lang)'%langDict['key']" tal:content="python:langDict['key']">Key</td>
<td tal:repeat="langId langIds"><div class="single-line"><textarea class="form-control form-control-sm" tal:attributes="name python:'%s_value_%s'%(langDict['key'],langId); disabled python:['','disabled'][int(langId in langDict.get('acquired',[]))]" tal:content="python:langDict.get(langId,'')"></textarea></div></td>
</tr>
<tr class="row_insert">
<tr class="row_insert form-group">
<td class="meta-sort text-center"><span class="btn btn-secondary btn-sm btn-add mr-1 w-100"><i class="fas fa-plus"></i></span></td>
<td><input class="form-control form-control-sm" type="text" name="_lang_dict_key_0" /></td>
<td tal:repeat="langId langIds"><div class="single-line"><textarea class="form-control form-control-sm" tal:attributes="name python:'_lang_dict_value_0_%s'%(langId)"></textarea></div></td>
</tr>
</tbody>
</table>
<div class="controls save">
<button title="Save Dictionary" name="btn" type="submit" class="btn btn-primary" value="BTN_SAVE" tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</button>
<button title="Save Dictionary" name="btn" type="submit" class="btn btn-secondary" value="BTN_SAVE" tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</button>
<button title="Delete Selected Dictionary Terms" name="btn" type="submit" class="btn btn-secondary" value="BTN_DELETE" tal:content="python:here.getZMILangStr('BTN_DELETE')">Delete</button>
</div>
</form>
Expand Down Expand Up @@ -242,17 +242,6 @@
/**
* Submit form with given parameters.
*/
function zmiFormSubmit(sender,d) {
var $fm = $(sender).closest("form");
var html = '';
for (var i in d) {
$('input[name="' + i + '"]',$fm).remove();
html += '<input type="hidden" name="' + i + '" value="' + d[i] +'"/>';
}
$fm
.append(html)
.submit();
}
function zmiFormSubmit(sender,d) {
var $fm = $(sender).closest("form");
if ('btn' in d) {
Expand Down Expand Up @@ -342,10 +331,12 @@

// Process td:first-child of the clone
$new_row.find('td.meta-sort').html(new_btn_html);
$new_row.removeAttr('class').attr('id',new_row_name);
$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($('input',$new_row));
// Reset the clone template
$where_insert.find('input:not([type="checkbox"]),textarea').each(function() {
$(this).val(undefined);
Expand Down
17 changes: 14 additions & 3 deletions Products/zms/zpt/ZMS/manage_users.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,21 @@ function zmiModalInsertUserOpen(context) {
</tal:block>
<div class="form-group row">
<div class="controls save">
<button type="submit" name="btn" class="btn btn-primary" value="BTN_SAVE" tal:condition="python:userObj is not None"><i class="fas fa-save"></i> <tal:block tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</tal:block></button>
<button type="submit" name="btn" class="btn btn-secondary" value="BTN_DELETE" tal:condition="python:userName in userNames"><i class="fas fa-times"></i> <tal:block tal:content="python:here.getZMILangStr('BTN_DELETE')">Delete</tal:block></button>
<button type="submit" name="btn" class="btn btn-primary" value="BTN_SAVE"
tal:condition="python:userObj is not None"
tal:content="python:here.getZMILangStr('BTN_SAVE')">
Save
</button>
<button type="submit" name="btn" class="btn btn-secondary" value="BTN_DELETE"
tal:condition="python:userName in userNames"
tal:content="python:here.getZMILangStr('BTN_DELETE')">
Delete
</button>
&nbsp;&nbsp;
<button type="submit" name="btn" class="btn btn-secondary" value="BTN_BACK" tal:content="python:here.getZMILangStr('BTN_BACK')">Back</button>
<button type="submit" name="btn" class="btn btn-secondary" value="BTN_BACK"
tal:content="python:here.getZMILangStr('BTN_BACK')">
Back
</button>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion Products/zms/zpt/ZMSFormatProvider/manage_charformats.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</div><!-- .form-group -->
<div class="form-group row">
<div class="controls save">
<button type="submit" name="btn" class="btn btn-primary" value="BTN_SAVE" tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</button>
<button type="submit" name="btn" class="btn btn-secondary" value="BTN_SAVE" tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</button>
<button type="submit" name="btn" class="btn btn-secondary" value="BTN_CLOSE" tal:content="python:here.getZMILangStr('BTN_CLOSE')">Close</button>
</div><!-- .controls.save -->
</div><!-- .form-group -->
Expand Down
2 changes: 1 addition & 1 deletion Products/zms/zpt/ZMSFormatProvider/manage_textformats.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

<div class="form-group row">
<div class="controls save">
<button type="submit" name="btn" class="btn btn-primary" value="BTN_SAVE" tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</button>
<button type="submit" name="btn" class="btn btn-secondary" value="BTN_SAVE" tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</button>
<button type="submit" name="btn" class="btn btn-secondary" value="BTN_CLOSE" tal:content="python:here.getZMILangStr('BTN_CLOSE')">Close</button>
</div>
</div><!-- .form-row -->
Expand Down
8 changes: 4 additions & 4 deletions Products/zms/zpt/ZMSIndex/manage_main.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function openWindow(url) {
<legend>ZMSIndex</legend>
<div id="zmsindex" class="collapse show">
<div class="card-body">
<div class="form-group zmi-form-container zms4-row mb-0">
<div class="form-group zmi-form-container zms4-row mb-0">
<div class="col-sm-12" data-label="ZMS-Clients">
<div class="zmi-sitemap-controls-container">
<div class="btn-group zmi-sitemap-controls">
Expand Down Expand Up @@ -149,9 +149,9 @@ function openWindow(url) {
tal:attributes="value python:zmscontext.operator_getattr(zmscontext,'index_names','')"/>
<div class="input-group-append input-group-btn">
<button class="btn btn-primary" name="btn" value="save"
onclick="$(this).parents('form').attr({action:self.location.href})">
<i class="icon-save fas fa-save"></i>
<tal:block tal:content="python:here.getZMILangStr('BTN_SAVE')"></tal:block>
onclick="$(this).parents('form').attr({action:self.location.href})"
tal:content="python:here.getZMILangStr('BTN_SAVE')">
Save
</button>
</div>
</div><!-- .input-group -->
Expand Down
15 changes: 9 additions & 6 deletions Products/zms/zpt/ZMSMetamodelProvider/manage_main.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@

<div class="form-group row m-2">
<div class="controls save m-0 p-0 container text-nowrap">
<button tal:condition="python:not metaObj['acquired']" type="submit" name="btn" class="btn btn-primary" value="BTN_SAVE" tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</button>
<button tal:condition="python:not metaObj['acquired']" type="submit" name="btn" class="btn btn-secondary" value="BTN_SAVE" tal:content="python:here.getZMILangStr('BTN_SAVE')">Save</button>
<button tal:condition="python:metaObj['acquired']" type="submit" name="btn" class="btn btn-primary" value="BTN_COPY" tal:content="python:here.getZMILangStr('BTN_COPY')">Copy</button>
<a href="./manage_main" class="btn btn-secondary" value="BTN_BACK" tal:content="python:here.getZMILangStr('BTN_BACK')">Back</a>
</div>
Expand Down Expand Up @@ -202,7 +202,7 @@

<tbody tal:define="req_attr_id_match python:request.get('attr_id') in objAttrIds">
<tr tal:repeat="objAttrId objAttrIds"
tal:attributes="class python:request.get('attr_id') and ( ( req_attr_id_match and request.get('attr_id')==objAttrId ) and 'zmi-selected table-warning' or ( ( not req_attr_id_match and ( len(request.get('attr_id'))>1 and request.get('attr_id') in objAttrId ) ) and 'zmi-selected table-warning' or '' ) );">
tal:attributes="class python:'form-group %s'%(request.get('attr_id','') and ( ( req_attr_id_match and request.get('attr_id')==objAttrId ) and 'zmi-selected table-warning' or ( ( not req_attr_id_match and ( len(request.get('attr_id'))>1 and ( request.get('attr_id') in objAttrId ) ) ) and 'zmi-selected table-warning' or '' )));">
<tal:block tal:define="
objAttr python:metaObjAttrs[objAttrIds.index(objAttrId)];
isMetaDictAttr python:int(objAttr['meta_type'] not in [0,'',False,None]);">
Expand Down Expand Up @@ -331,7 +331,7 @@

</tal:block>
</tr>
<tr class="row_insert">
<tr class="row_insert form-group">
<td class="meta-sort text-right"><span class="btn btn-secondary btn-sm btn-add mr-1 w-100"><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>
Expand Down Expand Up @@ -386,7 +386,8 @@
</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">
<tr class="form-group"
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"
Expand All @@ -402,7 +403,7 @@
</td>
</tr>
</tal:block>
<tr class="row_insert" tal:define="i python:0">
<tr class="row_insert form-group" tal:define="i python:0">
<td class="meta-sort text-right">
<span class="btn btn-secondary btn-sm btn-add mr-1 w-100"><i class="fas fa-plus"></i></span>
</td>
Expand Down Expand Up @@ -942,10 +943,12 @@ $(function(){

// Process td:first-child of the clone
$new_row.find('td.meta-sort').html(new_btn_html);
$new_row.removeAttr('class').attr('id',new_row_name);
$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);
Expand Down
12 changes: 7 additions & 5 deletions Products/zms/zpt/ZMSMetamodelProvider/manage_metas.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</thead>
<tbody>
<tal:block tal:define="metadictAttrIds python:here.getMetadictAttrs()">
<tr tal:repeat="metadictAttrId metadictAttrIds">
<tr tal:repeat="metadictAttrId metadictAttrIds" class="form-group">
<tal:block tal:define="global metadictAttr python:here.getMetadictAttr(metadictAttrId)">
<td class="meta-sort">
<input type="hidden" name="old_ids:list" tal:attributes="value python:metadictAttr['id']" />
Expand Down Expand Up @@ -162,7 +162,7 @@
</tal:block>
</tr>
</tal:block>
<tr class="row_insert">
<tr class="row_insert form-group">
<td class="meta-sort text-right"><span class="btn btn-add mr-1 btn-secondary btn-sm"><i class="fas fa-plus"></i></span></td>
<td class="meta-id"><input class="form-control form-control-sm" type="text" name="_id" /></td>
<td class="meta-name"><input class="form-control form-control-sm" type="text" name="_name" /></td>
Expand All @@ -182,13 +182,13 @@
</tbody>
</table>
<div class="controls save">
<button name="btn" type="button" class="btn btn-primary"
<button name="btn" type="button" class="btn btn-secondary"
hx-trigger="click"
hx-post="manage_changeMetaProperties"
hx-target="#zmi_manage_tabs_message"
hx-swap="outerHTML show:top"
hx-on:click="$ZMI.show_spinner(this)"
hx-on:htmx:after-request="renew_sort_options(this);$ZMI.reset_spinner(this);"
hx-on:htmx:after-request="renew_sort_options(this);$ZMI.reset_spinner(this)"
value="BTN_SAVE"
tal:content="python:here.getZMILangStr('BTN_SAVE')">
Save
Expand Down Expand Up @@ -386,10 +386,12 @@

// Process td:first-child of the clone
$new_row.find('td.meta-sort').html(new_btn_html);
$new_row.removeAttr('class').attr('id',new_row_name);
$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);
Expand Down

0 comments on commit a51dfff

Please sign in to comment.