Guest User

Untitled

a guest
Mar 20th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. function main()
  2. {
  3. // Extract template args
  4. var itemKind = decodeURIComponent(url.templateArgs["item_kind"]);
  5. var itemId = decodeURIComponent(url.templateArgs["item_id"]);
  6.  
  7. if (logger.isLoggingEnabled())
  8. {
  9. logger.log("json form submission for item:");
  10. logger.log("\tkind = " + itemKind);
  11. logger.log("\tid = " + itemId);
  12. }
  13.  
  14. if (typeof json !== "undefined")
  15. {
  16. // At this point the field names are e.g. prop_cm_name
  17. // and there are some extra values - hidden fields? These are fields from YUI's datepicker(s)
  18. // e.g. "template_x002e_form-ui_x002e_form-test_prop_my_date-entry":"2/19/2009"
  19. }
  20. else
  21. {
  22. if (logger.isWarnLoggingEnabled())
  23. {
  24. logger.warn("json object was undefined.");
  25. }
  26.  
  27. status.setCode(501, message);
  28. return;
  29. }
  30.  
  31. var repoFormData = new Packages.org.alfresco.repo.forms.FormData();
  32. var jsonKeys = json.keys();
  33. for ( ; jsonKeys.hasNext(); )
  34. {
  35. var nextKey = jsonKeys.next();
  36.  
  37. if (nextKey == "alf_redirect")
  38. {
  39. // store redirect url in model
  40. model.redirect = json.get(nextKey);
  41.  
  42. if (logger.isLoggingEnabled())
  43. {
  44. logger.log("found redirect: " + model.redirect);
  45. }
  46. }
  47. else
  48. {
  49. // add field to form data
  50. repoFormData.addFieldData(nextKey, json.get(nextKey));
  51. }
  52. }
  53.  
  54. var persistedObject = null;
  55. try
  56. {
  57. persistedObject = formService.saveForm(itemKind, itemId, repoFormData);
  58. }
  59. catch (error)
  60. {
  61. var msg = error.message;
  62.  
  63. if (logger.isLoggingEnabled())
  64. logger.log(msg);
  65.  
  66. if(msg.indexOf("(AlfrescoJS") != -1)
  67. {
  68. msg = msg.substring(0,msg.indexOf("(AlfrescoJS"));
  69. }
  70.  
  71. // get my custom errors here...
  72. if( msg.indexOf("MyError") != -1)
  73. {
  74. var index = msg.indexOf("MyError");
  75. msg = msg.substring(index+8);
  76. status.setCode(500, msg);
  77. }
  78.  
  79. if( msg.indexOf("TypeError:") != -1)
  80. {
  81. var index = msg.indexOf("TypeError:");
  82. msg = msg.substring(index+11);
  83. status.setCode(500, msg);
  84. }
  85.  
  86. if( msg.indexOf("Unknown") != -1)
  87. {
  88. var index = msg.indexOf("Unknown");
  89. msg = msg.substring(index+8);
  90. status.setCode(500, msg);
  91. }
  92.  
  93. if( msg.indexOf("unknown") != -1)
  94. {
  95. var index = msg.indexOf("unknown");
  96. msg = msg.substring(index+8);
  97. status.setCode(500, msg);
  98. }
  99.  
  100. if( msg.indexOf("Acesso negado") != -1)
  101. {
  102. var index = msg.indexOf("Acesso negado");
  103. msg = msg.substring(index);
  104. status.setCode(500, msg);
  105. }
  106.  
  107. if( msg.indexOf("Invalid") != -1)
  108. {
  109. var index = msg.indexOf("Invalid");
  110. msg = msg.substring(index);
  111. status.setCode(500, msg);
  112. }
  113.  
  114. if( msg.indexOf("Failed to execute supplied script:") != -1)
  115. {
  116. var index = msg.indexOf("Failed to execute supplied script:");
  117. msg = msg.substring(index+35);
  118. status.setCode(500, msg);
  119. }
  120.  
  121. if( msg.indexOf("ScriptExecutionListener doesn't implement") != -1)
  122. {
  123. var index = msg.indexOf("ScriptExecutionListener doesn't implement");
  124. msg = msg.substring(index);
  125. status.setCode(500, msg);
  126. }
  127.  
  128. if( msg.indexOf("invoking TaskListener: ") != -1)
  129. {
  130. var index = msg.indexOf("invoking TaskListener: ");
  131. msg = msg.substring(index+23);
  132. status.setCode(500, msg);
  133. }
  134.  
  135. // determine if the exception was a FormNotFoundException, if so return
  136. // 404 status code otherwise return 500
  137. else if (msg.indexOf("FormNotFoundException") != -1)
  138. {
  139. status.setCode(404, msg);
  140.  
  141. if (logger.isLoggingEnabled())
  142. logger.log("Returning 404 status code");
  143. }
  144. else
  145. {
  146. status.setCode(500, msg);
  147.  
  148. if (logger.isLoggingEnabled())
  149. logger.log("Returning 500 status code");
  150. }
  151.  
  152. return;
  153. }
  154.  
  155. model.persistedObject = persistedObject.toString();
  156. model.message = "Successfully persisted form for item [" + itemKind + "]" + itemId;
  157. }
  158.  
  159. main();
Add Comment
Please, Sign In to add comment