diff --git a/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgeBox_baseEdit.xml b/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgeBox_baseEdit.xml index f263ad7ab7cee51f8ea6815c3fdcbe6f90f152fd..a35a762c7077c8c3b32f1191140c5aedf1e9f493 100644 --- a/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgeBox_baseEdit.xml +++ b/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgeBox_baseEdit.xml @@ -53,7 +53,9 @@ <value> <string>"""\n This script edits a Knowledge Box instance used for saving a Gadget preferences.\n """\n -# XXX: How validation\n +from Products.Formulator.Errors import FormValidationError\n +from json import dumps\n +\n kw = {}\n request = context.REQUEST\n form = request.form\n @@ -61,6 +63,30 @@ fields = filter(lambda x: x.startswith(form_fields_main_prefix), form.keys())\n box = context.restrictedTraverse(box_relative_url)\n portal_selection = context.getPortalObject().portal_selections\n \n +# do validation\n +form = getattr(context,form_id)\n +try:\n + # Validate\n + form.validate_all_to_request(request, key_prefix=form_fields_main_prefix)\n +except FormValidationError, validation_errors:\n + # Pack errors into the request\n + field_errors = form.ErrorFields(validation_errors)\n + request.set(\'field_errors\', field_errors)\n + # we need form rendered in gadget mode\n + request.set(\'is_gadget_mode\', 1)\n + # Make sure editors are pushed back as values into the REQUEST object\n + for f in form.get_fields():\n + field_id = f.id\n + if request.has_key(field_id):\n + value = request.get(field_id)\n + if callable(value):\n + value(request)\n + # return validation failed code and rendered form\n + result = {\'content\': form(request, key_prefix=form_fields_main_prefix),\n + \'validation_status\': 0}\n + return dumps(result)\n +\n +form = request.form\n # get interesting for us fields and save\n listbox_selection_field_prefix = \'%s_my_listbox_selection_\' %form_fields_main_prefix\n for field in fields:\n @@ -74,15 +100,20 @@ for field in fields:\n portal_selection.setSelectionParamsFor(selection_name, params)\n kw[field.replace(\'%s_my_\' %form_fields_main_prefix, \'\')] = form[field]\n \n +# edit\n +box.edit(**kw)\n +\n +if not synchronous_mode:\n + # return JSON in asynchronous mode\n + result = {\'content\': \'\',\n + \'validation_status\': 1}\n + return dumps(result)\n +\n # determine redirect URL as passed from gadget preference form\n if gadget_redirect_url is None:\n # taking URL1 as the base of the original URL. \n # it works for both synchronous and asynchronous gadgets\n gadget_redirect_url = request[\'URL1\']\n - \n -# edit\n -box.edit(**kw)\n -\n request.RESPONSE.redirect(\'%s?portal_status_message=%s\'\n %(gadget_redirect_url, \n context.Base_translateString(\'Preference updated.\')))\n @@ -90,7 +121,7 @@ request.RESPONSE.redirect(\'%s?portal_status_message=%s\'\n </item> <item> <key> <string>_params</string> </key> - <value> <string>form_fields_main_prefix, box_relative_url, gadget_redirect_url=None</string> </value> + <value> <string>form_id, form_fields_main_prefix, box_relative_url, gadget_redirect_url=None, synchronous_mode=True</string> </value> </item> <item> <key> <string>id</string> </key> diff --git a/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgeBox_generateSubmitFormJavaScriptCode.xml b/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgeBox_generateSubmitFormJavaScriptCode.xml index 2c34b76ccf2ec7cf0060aa8821b982345910ef0d..c9685bb35314be5fb7d821d9296e0f5911e68c3f 100644 --- a/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgeBox_generateSubmitFormJavaScriptCode.xml +++ b/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgeBox_generateSubmitFormJavaScriptCode.xml @@ -51,10 +51,17 @@ <item> <key> <string>_body</string> </key> <value> <string>pad_relative_url = context.getRelativeUrl()\n -return \'\'\'onkeypress="submitGadgetPreferenceFormOnEnter(event, \'%s\',\'%s\');"\'\'\' \\\n - %(\'gadget_preference_%s_field\' %pad_relative_url.replace(\'/\', \'_\'), pad_relative_url)\n +edit_form_id = context.getSpecialiseValue().getEditFormId()\n +context.log(\'%s\' %edit_form_id)\n +\n +return \'\'\'onkeypress="submitGadgetPreferenceFormOnEnter(event, \'%s\',\'%s\', \'%s\');"\'\'\' \\\n + %(\'gadget_preference_%s_field\' %pad_relative_url.replace(\'/\', \'_\'), pad_relative_url, edit_form_id)\n </string> </value> </item> + <item> + <key> <string>_params</string> </key> + <value> <string></string> </value> + </item> <item> <key> <string>id</string> </key> <value> <string>KnowledgeBox_generateSubmitFormJavaScriptCode</string> </value> diff --git a/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgePad_viewColumnWidget.xml b/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgePad_viewColumnWidget.xml index 5e4b55eb577ff15906608c37e08049b8299b5ad1..2d3a09dbefea52746d4af04298744a077688da33 100644 --- a/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgePad_viewColumnWidget.xml +++ b/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/KnowledgePad_viewColumnWidget.xml @@ -126,7 +126,8 @@ tal:define="form_fields_main_prefix python: \'gadget_preference_%s_field\' %box_dom_id;">\n \n <!-- render edit gadget preferences form -->\n - <span tal:replace="structure python: edit_form_object(key_prefix=form_fields_main_prefix)"/>\n + <div class="edit-form-content"\n + tal:content="structure python: edit_form_object(key_prefix=form_fields_main_prefix)"/>\n \n <tal:block tal:condition="not: is_asynchronous_gadget">\n \n @@ -138,7 +139,10 @@ <button type="submit"\n i18n:translate="" \n i18n:domain="ui"\n - tal:attributes="onclick string:submitSynchronousGadgetPreferenceForm(\'${form_fields_main_prefix}\',\'${box_relative_url}\');\n + tal:attributes="onclick string:submitSynchronousGadgetPreferenceForm(\n + \'${form_fields_main_prefix}\',\n + \'${box_relative_url}\',\n + \'${edit_form_id}\');\n id string: submit_button_${box_dom_id};">Save</button>\n \n </tal:block>\n @@ -153,7 +157,8 @@ \'${view_form_id}\', \n \'${box_relative_url}\', \n \'${view_form_dom_id}\', \n - \'${form_fields_main_prefix}\');\n + \'${form_fields_main_prefix}\',\n + \'${edit_form_id}\');\n id string:submit_button_${box_dom_id};">Save</button>\n \n \n diff --git a/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/erp5_knowledge_box.js.xml b/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/erp5_knowledge_box.js.xml index a14dc3063bddbb5ef150a695a93a45633c5a01ad..c0e82a8fe5d74cbf046d8e60dee507f751e1b386 100644 --- a/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/erp5_knowledge_box.js.xml +++ b/bt5/erp5_knowledge_pad/SkinTemplateItem/portal_skins/erp5_knowledge_pad/erp5_knowledge_box.js.xml @@ -12,7 +12,7 @@ </item> <item> <key> <string>_EtagSupport__etag</string> </key> - <value> <string>ts00370324.82</string> </value> + <value> <string>ts07964628.69</string> </value> </item> <item> <key> <string>__name__</string> </key> @@ -175,34 +175,42 @@ function createDefaultPadOnServer(timeout, default_pad_group, return_url, mode){ success: function(data){checkForActivitiesOnServer(timeout, return_url, mode, default_pad_group);}});\n }\n \n -function submitGadgetPreferenceFormOnEnter(event, form_fields_main_prefix, box_relative_url){\n +function submitGadgetPreferenceFormOnEnter(event, \n + form_fields_main_prefix, \n + box_relative_url, \n + edit_form_id){\n /* This function can be used to submit gadget preferences form whenever\n an enter is pressed in form */\n - if(event.keyCode == 13){submitSynchronousGadgetPreferenceForm(form_fields_main_prefix, box_relative_url);}\n + if(event.keyCode == 13){submitSynchronousGadgetPreferenceForm(form_fields_main_prefix, \n + box_relative_url, \n + edit_form_id);}\n }\n \n function submitSynchronousGadgetPreferenceForm(\n form_fields_main_prefix, \n - box_relative_url){\n + box_relative_url,\n + edit_form_id){\n /* this will add respective gadget knowledge box relative url and\n gadget ERP5 preference form field_prefix (so multiple gadgets can \n safely coexist in one HTML page with one HTML form */\n redirect_url = window.location.protocol + "//" + window.location.host + window.location.pathname\n - $("form").append(\'<input type="hidden" name="box_relative_url" value="\' +box_relative_url + \'">\');\n - $("form").append(\'<input type="hidden" name="form_fields_main_prefix" value="\' +form_fields_main_prefix + \'">\');\n - $("form").append(\'<input type="hidden" name="gadget_redirect_url" value="\' +redirect_url + \'">\');\n - clickSaveButton(knowledge_box_edit_script_id); \n -};\n + $("form").append(\'<input type="hidden" name="box_relative_url" value="\' +box_relative_url + \'">\')\n + $("form").append(\'<input type="hidden" name="form_fields_main_prefix" value="\' +form_fields_main_prefix + \'">\')\n + $("form").append(\'<input type="hidden" name="gadget_redirect_url" value="\' +redirect_url + \'">\')\n + $("form").append(\'<input type="hidden" name="form_id" value="\' +edit_form_id + \'">\') \n + clickSaveButton(knowledge_box_edit_script_id)\n +}\n \n function submitAsynchronousGadgetPreferenceForm(\n form_dom_id, \n view_form_url, \n box_relative_url, \n visual_block_dom_id, \n - form_fields_main_prefix){\n + form_fields_main_prefix,\n + edit_form_id){\n /* Iterate over all possible form elements within edit form,\n collect them and send to server*/\n - var request_str = "box_relative_url=" + box_relative_url+ "&form_fields_main_prefix=" + form_fields_main_prefix + "&";\n + var request_str = "synchronous_mode:int=0&" + "box_relative_url=" + box_relative_url+ "&form_fields_main_prefix=" + form_fields_main_prefix + "&form_id="+edit_form_id + "&";\n \n //input tags\n $("#" + form_dom_id).find("input").each(\n @@ -234,12 +242,23 @@ function submitAsynchronousGadgetPreferenceForm(\n if(option.attr("selected")){request_str+=element.attr("name") + \'=\' + option.val() + \'&\';}\n }); }\n else{request_str+=name + \'=\' + value + \'&\';} });\n - \n + \n // save form preferences to remote server\n $.ajax({url: knowledge_box_edit_script_id + "?" + request_str,\n + dataType: "json",\n success: function (data){\n - updater(view_form_url, box_relative_url, visual_block_dom_id);\n - $("#" + form_dom_id).toggle();} });\n + if (data.validation_status){\n + // server side validation passed\n + updater(view_form_url, box_relative_url, visual_block_dom_id)\n + $("#" + form_dom_id).toggle()\n + // clean error messages\n + $("#" + form_dom_id + " span.error").remove()\n + }\n + else{\n + // server side validation failed show error message\n + $("#" + form_dom_id + " div.edit-form-content").html(data.content)\n + }\n + } });\n }\n \n function updateServerBoxColumnLayout(event, ui){\n @@ -493,7 +512,7 @@ $(document).ready(initialize);\n </item> <item> <key> <string>size</string> </key> - <value> <int>18244</int> </value> + <value> <int>19261</int> </value> </item> <item> <key> <string>title</string> </key> diff --git a/bt5/erp5_knowledge_pad/bt/revision b/bt5/erp5_knowledge_pad/bt/revision index 0fce07d0e34eb4c36d27c5eb87a2d7d3bcdec849..849eaf846afa36e3886600eca759f81d637bd064 100644 --- a/bt5/erp5_knowledge_pad/bt/revision +++ b/bt5/erp5_knowledge_pad/bt/revision @@ -1 +1 @@ -721 \ No newline at end of file +722 \ No newline at end of file