[gen] Added, on edit.pt (the unique Appy form) a handler window.onbeforeunload to warn the user that data can be lost or a lock can stay on the object.

This commit is contained in:
Gaetan Delannay 2013-01-18 14:32:29 +01:00
parent d42dffacad
commit b3ff087e8f
11 changed files with 76 additions and 60 deletions

View file

@ -333,6 +333,14 @@ function initSlaves() {
}
}
// Function used to submit the appy form on edit.pt
function submitAppyForm(button) {
var theForm = document.getElementById('appyForm');
// On which button has the user clicked?
theForm.button.value = button;
theForm.submit();
}
// Function used for triggering a workflow transition
function triggerTransition(transitionId, msg) {
var theForm = document.getElementById('triggerTransitionForm');
@ -517,8 +525,9 @@ function doAskPasswordReinit() {
// Function that finally posts the edit form after the user has confirmed that
// she really wants to post it.
function postConfirmedEditForm() {
var theForm = document.getElementById('appyEditForm');
var theForm = document.getElementById('appyForm');
theForm.confirmed.value = "True";
theForm.button.value = 'save';
theForm.submit();
}

View file

@ -14,16 +14,27 @@
tal:on-error="structure python: tool.manageError(error)">
<metal:prologue use-macro="context/ui/page/macros/prologue"/>
<form id="appyEditForm" name="appyEditForm" method="post" enctype="multipart/form-data"
tal:attributes="action python: contextObj.absolute_url()+'/do';
class python: test(confirmMsg, 'atBaseEditForm', 'enableUnloadProtection atBaseEditForm')">
<tal:comment replace="nothing">Warn the user that the form should be left via buttons</tal:comment>
<script type="text/javascript">
window.onbeforeunload = function(e){
theForm = document.getElementById('appyForm');
if (theForm.button.value == "") {
var e = e || window.event;
if (e) {e.returnValue = warn_leave_form;}
return warn_leave_form;
}
}
</script>
<form id="appyForm" name="appyForm" method="post" enctype="multipart/form-data"
tal:attributes="action python: contextObj.absolute_url()+'/do'">
<input type="hidden" name="action" value="Update"/>
<input type="hidden" name="button" value=""/>
<input type="hidden" name="page" tal:attributes="value page"/>
<input type="hidden" name="nav" tal:attributes="value request/nav|nothing"/>
<input type="hidden" name="confirmed" value="False"/>
<metal:show use-macro="context/ui/page/macros/show"/>
</form>
<script tal:condition="confirmMsg"
<script tal:condition="confirmMsg" type="text/javascript"
tal:content="python: 'askConfirm(\'script\', \'postConfirmedEditForm()\', \'%s\')' % confirmMsg">
</script>
<metal:footer use-macro="context/ui/page/macros/footer"/>

View file

@ -6,8 +6,7 @@
global allAreImported python:True">
<div metal:use-macro="context/ui/page/macros/prologue"/>
<script language="javascript">
<!--
<script type="text/javascript">
var importedElemsShown = false;
function toggleViewableElements() {
var rows = document.getElementsByName('importedElem');
@ -50,7 +49,6 @@
f.submit();
}
}
-->
</script>
<tal:comment replace="nothing">Form for importing several meetings at once.</tal:comment>
<form name="importElements"

View file

@ -11,7 +11,7 @@
</tal:include>
<tal:comment replace="nothing">Javascript messages</tal:comment>
<script language="javascript" tal:content="tool/getJavascriptMessages"></script>
<script type="text/javascript" tal:content="tool/getJavascriptMessages"></script>
<tal:comment replace="nothing">Global form for deleting an object</tal:comment>
<form id="deleteForm" method="post" action="do">
@ -230,7 +230,8 @@
tal:attributes="style python:test(historyExpanded, 'display:block', 'display:none')">
<div tal:define="ajaxHookId python: contextObj.UID() + '_history';"
tal:attributes="id ajaxHookId">
<script tal:content="python: 'askObjectHistory(\'%s\',\'%s\',%d,0)' % (ajaxHookId, contextObj.absolute_url(),historyMaxPerPage)">
<script type="text/javascript"
tal:content="python: 'askObjectHistory(\'%s\',\'%s\',%d,0)' % (ajaxHookId, contextObj.absolute_url(),historyMaxPerPage)">
</script>
</div>
</span>
@ -241,11 +242,7 @@
<tal:comment replace="nothing">The page footer.</tal:comment>
<metal:footer define-macro="footer">
<script language="javascript">
<!--
initSlaves();
-->
</script>
<script type="text/javascript">initSlaves();</script>
</metal:footer>
<tal:comment replace="nothing">
@ -260,31 +257,27 @@
<tal:comment replace="nothing">Previous</tal:comment>
<td tal:condition="python: previousPage and pageInfo['showPrevious']">
<tal:button condition="isEdit">
<input type="image" name="buttonPrevious"
tal:attributes="src string:$appUrl/ui/previous.png;
title python: _('page_previous')"/>
<input type="hidden" name="previousPage" tal:attributes="value previousPage"/>
<img style="cursor:pointer" onClick="submitAppyForm('previous')"
tal:attributes="src string:$appUrl/ui/previous.png; title python: _('page_previous')"/>
<input type="hidden" name="previousPage" tal:attributes="value previousPage"/>
</tal:button>
<tal:link condition="not: isEdit">
<a tal:attributes="href python: contextObj.getUrl(page=previousPage)">
<img tal:attributes="src string:$appUrl/ui/previous.png;
title python: _('page_previous')"/>
<img tal:attributes="src string:$appUrl/ui/previous.png; title python: _('page_previous')"/>
</a>
</tal:link>
</td>
<tal:comment replace="nothing">Save</tal:comment>
<td tal:condition="python: isEdit and pageInfo['showSave']">
<input type="image" name="buttonOk"
tal:attributes="src string:$appUrl/ui/save.png;
title python: _('object_save')"/>
<img style="cursor:pointer" onClick="submitAppyForm('save')"
tal:attributes="src string:$appUrl/ui/save.png; title python: _('object_save');"/>
</td>
<tal:comment replace="nothing">Cancel</tal:comment>
<td tal:condition="python: isEdit and pageInfo['showCancel']">
<input type="image" name="buttonCancel"
tal:attributes="src string:$appUrl/ui/cancel.png;
title python: _('object_cancel')"/>
<img style="cursor:pointer" onClick="submitAppyForm('cancel')"
tal:attributes="src string:$appUrl/ui/cancel.png; title python: _('object_cancel')"/>
</td>
<tal:edit condition="not: isEdit">
@ -309,18 +302,18 @@
<tal:comment replace="nothing">Refresh</tal:comment>
<td tal:condition="contextObj/isDebug">
<img title="Refresh" style="cursor:pointer; vertical-align:top"
tal:attributes="onClick python: 'href: window.location=\'%s\'' % contextObj.getUrl(mode=layoutType, page=page, refresh='yes');
src string: $appUrl/ui/refresh.png"/>
<a tal:attributes="href python: contextObj.getUrl(mode=layoutType, page=page, refresh='yes')">
<img title="Refresh" style="vertical-align:top"
tal:attributes="src string: $appUrl/ui/refresh.png"/>
</a>
</td>
<tal:comment replace="nothing">Next</tal:comment>
<td tal:condition="python: nextPage and pageInfo['showNext']">
<tal:button condition="isEdit">
<input type="image" name="buttonNext"
tal:attributes="src string:$appUrl/ui/next.png;
title python: _('page_next')"/>
<input type="hidden" name="nextPage" tal:attributes="value nextPage"/>
<img style="cursor:pointer" onClick="submitAppyForm('next')"
tal:attributes="src string:$appUrl/ui/next.png; title python: _('page_next')"/>
<input type="hidden" name="nextPage" tal:attributes="value nextPage"/>
</tal:button>
<tal:link condition="not: isEdit">
<a tal:attributes="href python: contextObj.getUrl(page=nextPage)">
@ -330,7 +323,7 @@
</tal:link>
</td>
<tal:comment replace="nothing">Workflow transitions</tal:comment>
<td tal:condition="python: layoutType in ('view', 'result')">
<td tal:condition="not: isEdit">
<metal:transitions use-macro="app/ui/page/macros/transitions"/>
</td>
</tr>

View file

@ -26,8 +26,8 @@
<tal:link repeat="name tool/getGlobalCssJs">
<link tal:condition="python: name.endswith('.css') and not ((dir == 'ltr') and (name == 'appyrtl.css'))"
rel="stylesheet" type="text/css" tal:attributes="href string:$appUrl/ui/$name"/>
<script tal:condition="python: name.endswith('.js')"
type="text/javascript" tal:attributes="src string:$appUrl/ui/$name"></script>
<script tal:condition="python: name.endswith('.js')" type="text/javascript"
tal:attributes="src string:$appUrl/ui/$name"></script>
</tal:link>
</head>

View file

@ -1,17 +1,17 @@
<tal:comment replace="nothing">View macro for a Computed.</tal:comment>
<metal:view define-macro="view">
<tal:sync condition="sync">
<span tal:condition="widget/plainText" tal:replace="value"/>
<span tal:condition="not: widget/plainText" tal:replace="structure value"/>
</tal:sync>
<tal:async condition="not: sync">
<div tal:define= "ajaxHookId python: contextObj.UID() + name"
tal:attributes = "id ajaxHookId">
<script language="javascript"
tal:content="python: 'askComputedField(\'%s\',\'%s\',\'%s\')' % (ajaxHookId, contextObj.absolute_url(), name)">
</script>
</div>
</tal:async>
<tal:sync condition="sync">
<span tal:condition="widget/plainText" tal:replace="value"/>
<span tal:condition="not: widget/plainText" tal:replace="structure value"/>
</tal:sync>
<tal:async condition="not: sync">
<div tal:define= "ajaxHookId python: contextObj.UID() + name"
tal:attributes = "id ajaxHookId">
<script type="text/javascript"
tal:content="python: 'askComputedField(\'%s\',\'%s\',\'%s\')' % (ajaxHookId, contextObj.absolute_url(), name)">
</script>
</div>
</tal:async>
</metal:view>
<tal:comment replace="nothing">Ajax-called view content of a non sync Computed field.</tal:comment>

View file

@ -42,7 +42,7 @@
<tal:comment replace="nothing">The icon for displaying the calendar popup</tal:comment>
<input type="hidden" tal:attributes="id name; name name"/>
<img tal:attributes="id string:${name}_img; src string: $appUrl/ui/calendar.gif"/>
<script tal:content="python: contextObj.getCalendarInit(name, years)"></script>
<script type="text/javascript" tal:content="python: contextObj.getCalendarInit(name, years)"></script>
<tal:hour condition="python: widget['format'] == 0">
<select tal:define="hours python:range(0,24);"
@ -109,7 +109,7 @@
<tal:comment replace="nothing">The icon for displaying the calendar popup</tal:comment>
<input type="hidden" tal:attributes="id fromName; name fromName"/>
<img tal:attributes="id string:${fromName}_img; src string: $appUrl/ui/calendar.gif"/>
<script tal:content="python: tool.getCalendarInit(fromName, years)"></script>
<script type="text/javascript" tal:content="python: tool.getCalendarInit(fromName, years)"></script>
</td>
</tr>
<tal:comment replace="nothing">To</tal:comment>
@ -140,7 +140,7 @@
<tal:comment replace="nothing">The icon for displaying the calendar popup</tal:comment>
<input type="hidden" tal:attributes="id toName; name toName"/>
<img tal:attributes="id string:${toName}_img; src string: $appUrl/ui/calendar.gif"/>
<script tal:content="python: tool.getCalendarInit(toName, years)"></script>
<script type="text/javascript" tal:content="python: tool.getCalendarInit(toName, years)"></script>
</td>
</tr>
</table>

View file

@ -164,7 +164,7 @@
</td>
</tr>
</table>
<script language="javascript"
<script type="text/javascript"
tal:content="python: 'initTab(\'tab_%s\', \'%s_1_%d\')' % (widget['name'], widget['name'], len(widget['widgets']))"></script>
</tal:asTabs>
</metal:group>