bind = {}; var library = { 'version': '4.0', "defineProperties": Object.defineProperties || function (obj, properties) { function convertToDescriptor(desc) { function hasProperty(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } function isCallable(v) { // NB: modify as necessary if other values than functions are callable. return typeof v === "function"; } if (typeof desc !== "object" || desc === null) throw new TypeError("bad desc"); var d = {}; if (hasProperty(desc, "enumerable")) d.enumerable = !!obj.enumerable; if (hasProperty(desc, "configurable")) d.configurable = !!obj.configurable; if (hasProperty(desc, "value")) d.value = obj.value; if (hasProperty(desc, "writable")) d.writable = !!desc.writable; if (hasProperty(desc, "get")) { var g = desc.get; if (!isCallable(g) && typeof g !== "undefined") throw new TypeError("bad get"); d.get = g; } if (hasProperty(desc, "set")) { var s = desc.set; if (!isCallable(s) && typeof s !== "undefined") throw new TypeError("bad set"); d.set = s; } if (("get" in d || "set" in d) && ("value" in d || "writable" in d)) throw new TypeError("identity-confused descriptor"); return d; } if (typeof obj !== "object" || obj === null) throw new TypeError("bad obj"); properties = Object(properties); var keys = Object.keys(properties); var descs = []; for (var i = 0; i < keys.length; i++) descs.push([keys[i], convertToDescriptor(properties[keys[i]])]); for (var i = 0; i < descs.length; i++) Object.defineProperty(obj, descs[i][0], descs[i][1]); return obj; }, 'typeOf': function(item){ if (item == null) return 'null'; if (item.$family != null) return item.$family(); if (item.constructor == Array) return 'array'; if (item.nodeName){ if (item.nodeType == 1) return 'element'; if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace'; } else if (typeof item.length == 'number'){ if (item.callee) return 'arguments'; //if ('item' in item) return 'collection'; } return typeof item; }, 'JSONDecode': function(string, secure){ if (!string || library.typeOf(string) != 'string') return null; return eval('(' + string + ')'); }, 'JSONEncode': function(obj){ if (obj && obj.toJSON) obj = obj.toJSON(); switch (library.typeOf(obj)){ case 'string': return '"' + obj.replace(/[\x00-\x1f\\"]/g, escape) + '"'; case 'array': var string = []; for (var i=0; i>> 0; for (var i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++){ if (this[i] === item) return i; } return -1; } }}; library.defineProperties(Array.prototype, o); })(); var wrapWorkContext = { "getTask": function(){return JSON.parse(workContext.getTaskOrTaskCompleted());}, "getWork": function(){return JSON.parse(workContext.getWork());}, "getActivity": function(){return JSON.parse(workContext.getActivity());}, "getTaskList": function(){return JSON.parse(workContext.getTaskList());}, "getTaskCompletedList": function(){return JSON.parse(workContext.getTaskCompletedList());}, "getReadList": function(){return JSON.parse(workContext.getReadList());}, "getReadCompletedList": function(){return JSON.parse(workContext.getReadCompletedList());}, "getJobTaskList": function(){return JSON.parse(workContext.getJobTaskList());}, "getJobTaskCompletedList": function(){return JSON.parse(workContext.getJobTaskCompletedList());}, "getJobReadList": function(){return JSON.parse(workContext.getJobReadList());}, "getJobReadCompletedList": function(){return JSON.parse(workContext.getJobReadCompletedList());}, "getTaskListByJob": function(){return JSON.parse(workContext.getJobTaskList());}, "getTaskCompletedListByJob": function(){return JSON.parse(workContext.getJobTaskCompletedList());}, "getReadListByJob": function(){return JSON.parse(workContext.getJobReadList());}, "getReadCompletedListByJob": function(){return JSON.parse(workContext.getJobReadCompletedList());}, "getReviewList": function(){return JSON.parse(workContext.getReviewList());}, "getWorkLogList": function(){return JSON.parse(workContext.getWorkLogList());}, "getAttachmentList": function(){return JSON.parse(workContext.getAttachmentList());}, "getRouteList": function(){return JSON.parse(workContext.getRouteList());}, "setTitle": function(title){workContext.setTitle(title);}, "getControl": function(){return null;}, "getInquiredRouteList": function(){return null;} }; //applications var includedScripts = []; var _self = this; var include = function(name, callback){ if (includedScripts.indexOf(name)==-1){ var json = JSON.parse(_self.workContext.getScript(name, includedScripts)); includedScripts = includedScripts.concat(json.importedList); if (json.text){ //MWF.Macro.exec(json.data.text, bind); var f = eval("(function(){return function(){\n"+json.text+"\n}})();"); returnValue = f.apply(bind); if (callback) callback.apply(bind); } } }; var define = function(name, fun, overwrite){ var over = true; if (overwrite===false) over = false; var o = {}; o[name] = {"value": fun, "configurable": over}; library.defineProperties(bind, o); }; var Dict = function(name){ var dictionary = _self.dictionary; this.name = name; this.get = function(path){ return JSON.parse(dictionary.select(this.name, path)); }; this.set = function(path, value){ try { dictionary.update(this.name, library.JSONEncode(value), path); return true; }catch(e){ return false; } }; this.add = function(path, value){ try { dictionary.insert(this.name, library.JSONEncode(value), path); return true; }catch(e){ return false; } }; }; if ((typeof JSON) == 'undefined'){ JSON = {}; } JSON.validate = function(string){ string = string.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''); return (/^[\],:{}\s]*$/).test(string); }; JSON.encode = JSON.stringify ? function(obj){ return JSON.stringify(obj); } : function(obj){ if (obj && obj.toJSON) obj = obj.toJSON(); switch (typeof obj){ case 'string': return '"' + obj.replace(/[\x00-\x1f\\"]/g, escape) + '"'; case 'array': var string = []; for (var i=0; i++i) ? functionArguments[i] : null; failure = (n>++i) ? functionArguments[i] : null; parameters.each(function(p, x){ parameter[p] = (n>++i) ? functionArguments[i] : null; }); if (service.method && (service.method.toLowerCase()==="post" || service.method.toLowerCase()==="put")){ data = (n>++i) ? functionArguments[i] : null; } }else{ parameters.each(function(p, x){ parameter[p] = (n>x) ? functionArguments[x] : null; }); if (service.method && (service.method.toLowerCase()==="post" || service.method.toLowerCase()==="put")){ data = (n>++i) ? functionArguments[i] : null; } success = (n>++i) ? functionArguments[i] : null; failure = (n>++i) ? functionArguments[i] : null; } return _self.invoke({"name": key, "data": data, "parameter": parameter, "success": success, "failure": failure}); }; }; var createMethod = function(service, key){ var jaxrsUri = service.uri; var re = new RegExp("\{.+?\}", "g"); var replaceWords = jaxrsUri.match(re); var parameters = []; if (replaceWords) parameters = replaceWords.map(function(s){ return s.substring(1,s.length-1); }); this[key] = invokeFunction.call(this, service, parameters, key); }; Object.keys(this.actions).forEach(function(key){ var service = this.actions[key]; if (service.uri) if (!this[key]) createMethod.call(this, service, key); }, this); this.invoke = function(option){ // { // "name": "", // "data": "", // "parameter": "",, // "success": function(){} // "failure": function(){} // } if (this.actions[option.name]){ var uri = this.actions[option.name].uri; var method = this.actions[option.name].method || "get"; if (option.parameter){ Object.keys(option.parameter).forEach(function(key){ var v = option.parameter[key]; uri = uri.replace("{"+key+"}", v); }); } var res = null; try{ switch (method.toLowerCase()){ case "get": res = bind.applications.getQuery(this.root, uri); break; case "post": res = bind.applications.postQuery(this.root, uri, JSON.stringify(option.data)); break; case "put": res = bind.applications.putQuery(this.root, uri, JSON.stringify(option.data)); break; case "delete": res = bind.applications.deleteQuery(this.root, uri); break; default: res = bind.applications.getQuery(this.root, uri); } if (res && res.getType().toString()==="success"){ var json = JSON.parse(res.toString()); if (option.success) option.success(json); }else{ if (option.failure) option.failure(((res) ? JSON.parse(res.toString()) : null)); } }catch(e){ if (option.failure) option.failure(e); } } }; } })(); _Action.applications = this.applications; var _Actions = { "loadedActions": {}, "load": function(root){ if (this.loadedActions[root]) return this.loadedActions[root]; var jaxrsString = bind.applications.describeApi(root); var json = JSON.parse(jaxrsString.toString()); if (json && json.jaxrs){ var actionObj = {}; json.jaxrs.each(function(o){ if (o.methods && o.methods.length){ var actions = {}; o.methods.each(function(m){ var o = {"uri": "/"+m.uri}; if (m.method) o.method = m.method; if (m.enctype) o.enctype = m.enctype; actions[m.name] = o; }.bind(this)); actionObj[o.name] = new bind.Action(root, actions); } }.bind(this)); this.loadedActions[root] = actionObj; return actionObj; } return null; } }; bind.Actions = _Actions; try{ oPrint = oPrint; }catch(e){ oPrint = print } print = function(str, type){ var d = new Date(); var t = (type || "PRINT").toUpperCase(); var l = "[Script]"; oPrint(d.format("db")+"."+d.getMilliseconds()+" "+t+" "+l+" "+str); } bind.print = print; echo = print; bind.echo = print; bind.library = library; bind.data = this.data; bind.workContext = wrapWorkContext; bind.service = this.webservicesClient; bind.org = _org; bind.Action = _Action; //bind.organization = this.organization; bind.include = include; bind.define = define; bind.Dict = Dict; bind.form = null; bind.body = { "set": function(data){ if ((typeof data)==="string"){ body.set(data); } if ((typeof data)==="object"){ body.set(JSON.encode(data)); } } }; bind.headers = { "put": function(name, value){ try{ if ((typeof name)==="object"){ var _keys = Object.keys(name); for (var i=0; i<_keys.length; i++){ if (jaxrsHead) jaxrsHead.put(_keys[i], name[_keys[i]]); } }else{ if (jaxrsHead) jaxrsHead.put(name, value); } }catch(e){} }, "remove": function(name){ try{ if (jaxrsHead)jaxrsHead.remove(name); }catch(e){} } }; bind.parameters = { "put": function(name, value){ if ((typeof name)==="object"){ var _keys = Object.keys(name); for (var i=0; i<_keys.length; i++){ if (parameters) parameters.put(_keys[i], name[_keys[i]]); } }else{ if (parameters) parameters.put(name, value); } }, "remove": function(name){ try{ if (parameters) parameters.remove(name); }catch(e){} } }; //bind.parameters = this.parameters || null; bind.response = (function(){ if (this.jaxrsResponse){ if (this.jaxrsResponse.get()){ if (JSON.validate(this.jaxrsResponse.get())){ return { "status": this.jaxrsResponse.status, "value": JSON.decode(this.jaxrsResponse.get()) }; }else{ return { "status": this.jaxrsResponse.status, "value": this.jaxrsResponse.value }; } }else{ return {"status": this.jaxrsResponse.status}; } }else{ var _self = this; return { "get": function(){ if (_self.jaxrsResponse.get()){ if (JSON.validate(_self.jaxrsResponse.get())){ return { "status": _self.jaxrsResponse.status, "value": JSON.decode(_self.jaxrsResponse.get()) }; }else{ return { "status": _self.jaxrsResponse.status, "value": _self.jaxrsResponse.value }; } }else{ return {"status": _self.jaxrsResponse.status}; } } } } }).apply(this); bind.assginData = { "data": null, "get": function(){ this.data = JSON.decode(assignData.get()); return this.data; }, "set": function(data){ assignData.set(JSON.encode(data || this.data)); } }; bind.assignData = bind.assginData; bind.expire = { "setHour": function(hour){ try{expire.setHour(hour);}catch(e){} }, "setWorkHour": function(hour){ try{expire.setWorkHour(hour);}catch(e){} }, "setDate": function(date){ try{expire.setDate(date);}catch(e){} } }; bind.request = { "getBody": function(){ try{ return JSON.parse(serviceValue); }catch(e){ return null } } }