Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main()
- {
- // Extract template args
- var itemKind = decodeURIComponent(url.templateArgs["item_kind"]);
- var itemId = decodeURIComponent(url.templateArgs["item_id"]);
- if (logger.isLoggingEnabled())
- {
- logger.log("json form submission for item:");
- logger.log("\tkind = " + itemKind);
- logger.log("\tid = " + itemId);
- }
- if (typeof json !== "undefined")
- {
- // At this point the field names are e.g. prop_cm_name
- // and there are some extra values - hidden fields? These are fields from YUI's datepicker(s)
- // e.g. "template_x002e_form-ui_x002e_form-test_prop_my_date-entry":"2/19/2009"
- }
- else
- {
- if (logger.isWarnLoggingEnabled())
- {
- logger.warn("json object was undefined.");
- }
- status.setCode(501, message);
- return;
- }
- var repoFormData = new Packages.org.alfresco.repo.forms.FormData();
- var jsonKeys = json.keys();
- for ( ; jsonKeys.hasNext(); )
- {
- var nextKey = jsonKeys.next();
- if (nextKey == "alf_redirect")
- {
- // store redirect url in model
- model.redirect = json.get(nextKey);
- if (logger.isLoggingEnabled())
- {
- logger.log("found redirect: " + model.redirect);
- }
- }
- else
- {
- // add field to form data
- repoFormData.addFieldData(nextKey, json.get(nextKey));
- }
- }
- var persistedObject = null;
- try
- {
- persistedObject = formService.saveForm(itemKind, itemId, repoFormData);
- }
- catch (error)
- {
- var msg = error.message;
- if (logger.isLoggingEnabled())
- logger.log(msg);
- if(msg.indexOf("(AlfrescoJS") != -1)
- {
- msg = msg.substring(0,msg.indexOf("(AlfrescoJS"));
- }
- // get my custom errors here...
- if( msg.indexOf("MyError") != -1)
- {
- var index = msg.indexOf("MyError");
- msg = msg.substring(index+8);
- status.setCode(500, msg);
- }
- if( msg.indexOf("TypeError:") != -1)
- {
- var index = msg.indexOf("TypeError:");
- msg = msg.substring(index+11);
- status.setCode(500, msg);
- }
- if( msg.indexOf("Unknown") != -1)
- {
- var index = msg.indexOf("Unknown");
- msg = msg.substring(index+8);
- status.setCode(500, msg);
- }
- if( msg.indexOf("unknown") != -1)
- {
- var index = msg.indexOf("unknown");
- msg = msg.substring(index+8);
- status.setCode(500, msg);
- }
- if( msg.indexOf("Acesso negado") != -1)
- {
- var index = msg.indexOf("Acesso negado");
- msg = msg.substring(index);
- status.setCode(500, msg);
- }
- if( msg.indexOf("Invalid") != -1)
- {
- var index = msg.indexOf("Invalid");
- msg = msg.substring(index);
- status.setCode(500, msg);
- }
- if( msg.indexOf("Failed to execute supplied script:") != -1)
- {
- var index = msg.indexOf("Failed to execute supplied script:");
- msg = msg.substring(index+35);
- status.setCode(500, msg);
- }
- if( msg.indexOf("ScriptExecutionListener doesn't implement") != -1)
- {
- var index = msg.indexOf("ScriptExecutionListener doesn't implement");
- msg = msg.substring(index);
- status.setCode(500, msg);
- }
- if( msg.indexOf("invoking TaskListener: ") != -1)
- {
- var index = msg.indexOf("invoking TaskListener: ");
- msg = msg.substring(index+23);
- status.setCode(500, msg);
- }
- // determine if the exception was a FormNotFoundException, if so return
- // 404 status code otherwise return 500
- else if (msg.indexOf("FormNotFoundException") != -1)
- {
- status.setCode(404, msg);
- if (logger.isLoggingEnabled())
- logger.log("Returning 404 status code");
- }
- else
- {
- status.setCode(500, msg);
- if (logger.isLoggingEnabled())
- logger.log("Returning 500 status code");
- }
- return;
- }
- model.persistedObject = persistedObject.toString();
- model.message = "Successfully persisted form for item [" + itemKind + "]" + itemId;
- }
- main();
Add Comment
Please, Sign In to add comment