initialScriptText.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. bind = {};
  2. var library = {
  3. 'version': '4.0',
  4. "defineProperties": Object.defineProperties || function (obj, properties) {
  5. function convertToDescriptor(desc) {
  6. function hasProperty(obj, prop) {
  7. return Object.prototype.hasOwnProperty.call(obj, prop);
  8. }
  9. function isCallable(v) {
  10. // NB: modify as necessary if other values than functions are callable.
  11. return typeof v === "function";
  12. }
  13. if (typeof desc !== "object" || desc === null)
  14. throw new TypeError("bad desc");
  15. var d = {};
  16. if (hasProperty(desc, "enumerable"))
  17. d.enumerable = !!obj.enumerable;
  18. if (hasProperty(desc, "configurable"))
  19. d.configurable = !!obj.configurable;
  20. if (hasProperty(desc, "value"))
  21. d.value = obj.value;
  22. if (hasProperty(desc, "writable"))
  23. d.writable = !!desc.writable;
  24. if (hasProperty(desc, "get")) {
  25. var g = desc.get;
  26. if (!isCallable(g) && typeof g !== "undefined")
  27. throw new TypeError("bad get");
  28. d.get = g;
  29. }
  30. if (hasProperty(desc, "set")) {
  31. var s = desc.set;
  32. if (!isCallable(s) && typeof s !== "undefined")
  33. throw new TypeError("bad set");
  34. d.set = s;
  35. }
  36. if (("get" in d || "set" in d) && ("value" in d || "writable" in d))
  37. throw new TypeError("identity-confused descriptor");
  38. return d;
  39. }
  40. if (typeof obj !== "object" || obj === null)
  41. throw new TypeError("bad obj");
  42. properties = Object(properties);
  43. var keys = Object.keys(properties);
  44. var descs = [];
  45. for (var i = 0; i < keys.length; i++)
  46. descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
  47. for (var i = 0; i < descs.length; i++)
  48. Object.defineProperty(obj, descs[i][0], descs[i][1]);
  49. return obj;
  50. },
  51. 'typeOf': function(item){
  52. if (item == null) return 'null';
  53. if (item.$family != null) return item.$family();
  54. if (item.constructor == Array) return 'array';
  55. if (item.nodeName){
  56. if (item.nodeType == 1) return 'element';
  57. if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
  58. } else if (typeof item.length == 'number'){
  59. if (item.callee) return 'arguments';
  60. //if ('item' in item) return 'collection';
  61. }
  62. return typeof item;
  63. },
  64. 'JSONDecode': function(string, secure){
  65. if (!string || library.typeOf(string) != 'string') return null;
  66. return eval('(' + string + ')');
  67. },
  68. 'JSONEncode': function(obj){
  69. if (obj && obj.toJSON) obj = obj.toJSON();
  70. switch (library.typeOf(obj)){
  71. case 'string':
  72. return '"' + obj.replace(/[\x00-\x1f\\"]/g, escape) + '"';
  73. case 'array':
  74. var string = [];
  75. for (var i=0; i<obj.length; i++){
  76. var json = library.JSONEncode(obj[i]);
  77. if (json) string.push(json);
  78. }
  79. return '[' + string + ']';
  80. case 'object': case 'hash':
  81. var string = [];
  82. for (key in obj){
  83. var json = library.JSONEncode(obj[key]);
  84. if (json) string.push(library.JSONEncode(key) + ':' + json);
  85. }
  86. return '{' + string + '}';
  87. case 'number': case 'boolean': return '' + obj;
  88. case 'null': return 'null';
  89. }
  90. return null;
  91. }
  92. };
  93. (function(){
  94. var o={"indexOf": {
  95. "value": function(item, from){
  96. var length = this.length >>> 0;
  97. for (var i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++){
  98. if (this[i] === item) return i;
  99. }
  100. return -1;
  101. }
  102. }};
  103. library.defineProperties(Array.prototype, o);
  104. })();
  105. var wrapWorkContext = {
  106. "getTask": function(){return library.JSONDecode(workContext.getCurrentTaskCompleted());},
  107. "getWork": function(){return library.JSONDecode(workContext.getWork());},
  108. "getActivity": function(){return library.JSONDecode(workContext.getActivity());},
  109. "getTaskList": function(){return library.JSONDecode(workContext.getTaskList());},
  110. "getWorkLogList": function(){return library.JSONDecode(workContext.getWorkLogList());},
  111. "getAttachmentList": function(){return library.JSONDecode(workContext.getAttachmentList());},
  112. "getRouteList": function(){return library.JSONDecode(workContext.getRouteList());},
  113. "getInquiredRouteList": function(){return library.JSONDecode(workContext.getInquiredRouteList());},
  114. "setTitle": function(title){workContext.setTitle(title);},
  115. "getControl": function(){return null;}
  116. };
  117. var includedScripts = [];
  118. var _self = this;
  119. var include = function(name, callback){
  120. if (includedScripts.indexOf(name)==-1){
  121. var json = library.JSONDecode(_self.workContext.getScript(name, includedScripts));
  122. includedScripts = includedScripts.concat(json.importedList);
  123. if (json.text){
  124. MWF.Macro.exec(json.data.text, bind);
  125. if (callback) callback.apply(bind);
  126. }
  127. }
  128. };
  129. var define = function(name, fun, overwrite){
  130. var over = true;
  131. if (overwrite===false) over = false;
  132. var o = {};
  133. o[name] = {"value": fun, "configurable": over};
  134. library.defineProperties(bind, o);
  135. };
  136. var Dict = function(name){
  137. var dictionary = _self.dictionary;
  138. this.name = name;
  139. this.get = function(path){
  140. return library.JSONDecode(dictionary.select(this.name, path));
  141. };
  142. this.set = function(path, value){
  143. try {
  144. dictionary.update(this.name, library.JSONEncode(value), path);
  145. return true;
  146. }catch(e){
  147. return false;
  148. }
  149. };
  150. this.add = function(path, value){
  151. try {
  152. dictionary.insert(this.name, library.JSONEncode(value), path);
  153. return true;
  154. }catch(e){
  155. return false;
  156. }
  157. };
  158. };
  159. bind.library = library;
  160. bind.data = this.data;
  161. bind.workContext = wrapWorkContext;
  162. bind.service = this.webserviceClient;
  163. bind.org = this.organization;
  164. bind.include = include;
  165. bind.define = define;
  166. bind.Dict = Dict;
  167. bind.form = null;
  168. bind.body = this.body || null;
  169. bind.parameters = this.parameters || null;