[gen] Integrated ckeditor inline editing via boolean parameter field.inlineEdit.

This commit is contained in:
Gaetan Delannay 2013-03-29 14:50:12 +01:00
parent 48c7c50122
commit 4e09a40807
6 changed files with 65 additions and 8 deletions

View file

@ -59,6 +59,14 @@ function XhrObject() { // Wraps a XmlHttpRequest object
this.info = {}; /* An associative array for putting anything else. */
}
/* When inserting HTML at some DOM node in a page via Ajax, scripts defined in
this chunk of HTML are not executed. This function, typically used as "onGet"
param for the askAjaxChunk function below, will evaluate those scripts. */
function evalInnerScripts(xhrObject, hookElem) {
var scripts = hookElem.getElementsByTagName('script');
for (var i=0; i<scripts.length; i++) { eval(scripts[i].innerHTML) }
}
function getAjaxChunk(pos) {
// This function is the callback called by the AJAX machinery (see function
// askAjaxChunk below) when an Ajax response is available.
@ -208,7 +216,8 @@ function askField(hookId, objectUrl, layoutType, showChanges){
var fieldName = hookId.split('_')[1];
var params = {'fieldName': fieldName, 'layoutType': layoutType,
'showChanges': showChanges};
askAjaxChunk(hookId, 'GET', objectUrl, 'widgets/show', 'fieldAjax', params);
askAjaxChunk(hookId, 'GET', objectUrl, 'widgets/show', 'fieldAjax', params,
null, evalInnerScripts);
}
// Function used by checkbox widgets for having radio-button-like behaviour

View file

@ -340,3 +340,14 @@
<span tal:replace="structure messages"></span>
</div>
</metal:message>
<tal:comment replace="nothing">
Save the content of a rich field and return its consult view.
Requires request/fieldContent.
</tal:comment>
<metal:save define-macro="saveField"
tal:define="fieldName request/fieldName;
fieldContent request/fieldContent;
dummy python: contextObj.updateField(fieldName, fieldContent)">
<metal:call use-macro="app/ui/widgets/show/macros/fieldAjax"/>
</metal:save>

View file

@ -90,7 +90,7 @@
<tal:comment replace="nothing">Call the previous macro, but from Ajax.</tal:comment>
<metal:afield define-macro="fieldAjax"
tal:define="widgetName request/fieldName;
layoutType request/layoutType;
layoutType python: request.get('layoutType', 'view');
showChanges python: request.get('showChanges', 'False') == 'True';
widget python: contextObj.getAppyType(widgetName, asDict=True);
page widget/pageName">

View file

@ -1,6 +1,7 @@
<tal:comment replace="nothing">View macro for a String.</tal:comment>
<metal:view define-macro="view"
tal:define="fmt widget/format; isUrl widget/isUrl">
tal:define="fmt widget/format; isUrl widget/isUrl;
mayAjaxEdit python: not showChanges and widget['inlineEdit'] and contextObj.mayEdit(widget['writePermission'])">
<span tal:condition="python: fmt in (0, 3)">
<ul tal:condition="python: value and isMultiple">
<li tal:repeat="sv value"><i tal:content="structure sv"></i></li>
@ -20,9 +21,16 @@
<span tal:condition="python: value and (fmt == 1)"
tal:replace="structure python: contextObj.formatText(value, format='html')"/>
<tal:comment replace="nothing">XHTML text</tal:comment>
<div tal:condition="python: value and (fmt == 2)" class="xhtml">
<span tal:replace="structure value"/>
</div>
<tal:xhtml condition="python: value and (fmt == 2)">
<div tal:condition="not: mayAjaxEdit" class="xhtml" tal:content="structure value"></div>
<div tal:condition="mayAjaxEdit" class="xhtml" contenteditable="true"
tal:attributes="id python: '%s_%s_ck' % (contextObj.UID(), name)"
tal:content="structure value">
</div>
<script tal:condition="mayAjaxEdit"
tal:content="python: contextObj.getEditorInlineInit(name)">
</script>
</tal:xhtml>
<input type="hidden" tal:condition="masterCss"
tal:attributes="class masterCss; value rawValue; name name; id name"/>
</metal:view>