Commit 9ceadf09 authored by Sergey Antonovich's avatar Sergey Antonovich 🇯🇵

Update devTools-Interpreter.md

parent d9154613
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
* Добавить скрипт в интерпретатор и использовать. * Добавить скрипт в интерпретатор и использовать.
```javascript ```javascript
function devTools(){let accessData=false;let formData=false;let formUUID=false;this.load=function(dataUUID){var content=this.api('asforms/data/'+dataUUID);accessData=(content.errorCode!='13');formUUID=dataUUID;formData=content.data;return this;};this.getData=function(){if(!accessData)return;return formData;};this.getUUID=function(){if(!accessData)return;return formUUID;};this.getDocumentId=function(dataUUID){return ""+this.api('formPlayer/documentIdentifier?dataUUID='+dataUUID,{},'GET',true)};this.getDataUUID=function(documentId){return this.api('asforms/data/document?dataUUID='+documentId);};this.getValue=function(){if(!accessData)return;var data;var args={c:arguments[0],ot:arguments[1],b:arguments[2],o:arguments[3]};if(typeof(args.c)==='string'&&typeof(args.b)==='number'){formData.forEach(function(item){if(item.id==args.ot){item.data.forEach(function(bItem){if(bItem.id.indexOf(args.c+'-b'+args.b)!==-1){data=(args.o)?bItem[args.o]:bItem;return;}});return;}});}else{formData.forEach(function(item){if(item.id==args.c){data=(args.ot)?item[args.ot]:item;return;}});}return data;};this.setValue=function(){if(!accessData)return;var args={c:arguments[0],vt:arguments[1],ob:arguments[2],v:arguments[3],o:arguments[4]};if(typeof(args.c)==='string'&&typeof(args.ob)==='number'){if(args.ob==0)args.ob=1;formData.forEach(function(item){if(item.id==args.vt){item.data.forEach(function(bItem){if(bItem.id.indexOf(args.c+'-b'+args.ob)!==-1){if(typeof(args.v)==='object')for(var aItem in args.v)bItem[aItem]=args.v[aItem];else bItem[(args.o)?args.o:'value']=args.v;return;}});return;}});}else{formData.forEach(function(item){if(item.id==args.c){if(typeof(args.vt)==='object')for(var aItem in args.vt)item[aItem]=args.vt[aItem];else item[(args.ob)?args.ob:'value']=args.vt;return;}});}};this.getRowCount=function(tableID){if(!accessData)return;var len=0;formData.forEach(function(item){if(item.id==tableID){item.data.forEach(function(tblItem){var regex=tblItem.id.match(/\-b(\d+)/);if(regex&&parseInt(regex[1])>len)len++;});return;}});return len;};this.convertTable=function(data){if(!accessData)return;var conArr=[];var b;data.forEach(function(item){if(item.id.indexOf('-b')!==-1&&(b=item.id.match(/(.+)\-b(\d+)/))){if((b[2] in conArr)===false)conArr[b[2]]={};conArr[b[2]][b[1]]=item;return;}});for(var i=0;i<conArr.length;i++)if(conArr[i]==null)conArr.splice(i--,1);return conArr;};this.save=function(){if(!accessData)return;var save=this.api('asforms/data/save',{uuid:formUUID,data:'"data":'+JSON.stringify(formData)},'POST');return (save=='200');};this.destroy=function(){accessData=formData=formUUID=false;};this.api=function(method,params,type,dataText){if(!method)return;if(!type)type='GET';var host="http://127.0.0.1:8080/Synergy/rest/api/";var client=new org.apache.commons.httpclient.HttpClient();var creds=new org.apache.commons.httpclient.UsernamePasswordCredentials(login,password);client.getParams().setAuthenticationPreemptive(true);client.getState().setCredentials(org.apache.commons.httpclient.auth.AuthScope.ANY,creds);switch(type){case 'GET':var _p=[];for(var p in params)_p.push(p+'='+params[p]);var api = new org.apache.commons.httpclient.methods.GetMethod(host+method+_p.join('&amp'));api.setRequestHeader("Content-type","application/json");client.executeMethod(api);var result=api.getResponseBodyAsString();break;case 'POST':var api=new org.apache.commons.httpclient.methods.PostMethod(host+method);for(var p in params)api.addParameter(p,params[p]);api.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=utf-8");var result=client.executeMethod(api);break;default:return;}api.releaseConnection();return (!dataText?JSON.parse(result):result);};this.log=function(data){var logViewer=function(data){if(typeof(data)!='string')data=JSON.stringify(data,null,4);data=data.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');return data.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,function(match){var cls='number';if(/^"/.test(match)){cls=(/:$/.test(match)?'key':'string');}else if(/true|false/.test(match)){cls='boolean';}else if(/null/.test(match)){cls='null';}return '<span class="log-color-'+cls+'">'+match+'</span>';});};data='<pre style="color:#fff;background:#282828;border:0;font-size:14px;">'+logViewer(data)+'</pre>';var styleW='.log{width:850px;max-height:540px;border:1px solid #b3b3b3;border-radius:3px;padding:8px;background:#282828;color:#fff;overflow:auto;}';var styleC='.log-color-key{color:#ff7a00;}.log-color-string{color:#f9f9b3;}.log-color-null{color:#9771ff;}.log-color-number{color:#00b3ff;}.log-color-boolean{color:#3ef38a;}';var styleWP='.alert-success{color:rgba(0,0,0,1);background-color:#dedede;border-color:#b3b3b3;}';var window='<style>'+styleWP+styleW+styleC+'</style><div class="log">'+data+'</div>';return window;};return this;}; function devTools(){let accessData=false;let formData=false;let formUUID=false;this.load=function(dataUUID){var content=this.api('asforms/data/'+dataUUID);accessData=(content.errorCode!='13');formUUID=dataUUID;formData=content.data;return this;};this.getData=function(){if(!accessData)return;return formData;};this.getUUID=function(){if(!accessData)return;return formUUID;};this.getDocumentId=function(dataUUID){return this.api('asforms/data/document?dataUUID='+dataUUID)};this.getDataUUID=function(documentId){return ""+this.api('formPlayer/getAsfDataUUID?documentID='+documentId,{},'GET',true);};this.getValue=function(){if(!accessData)return;var data;var args={c:arguments[0],ot:arguments[1],b:arguments[2],o:arguments[3]};if(typeof(args.c)==='string'&&typeof(args.b)==='number'){formData.forEach(function(item){if(item.id==args.ot){item.data.forEach(function(bItem){if(bItem.id.indexOf(args.c+'-b'+args.b)!==-1){data=(args.o)?bItem[args.o]:bItem;return;}});return;}});}else{formData.forEach(function(item){if(item.id==args.c){data=(args.ot)?item[args.ot]:item;return;}});}return data;};this.setValue=function(){if(!accessData)return;var args={c:arguments[0],vt:arguments[1],ob:arguments[2],v:arguments[3],o:arguments[4]};if(typeof(args.c)==='string'&&typeof(args.ob)==='number'){if(args.ob==0)args.ob=1;formData.forEach(function(item){if(item.id==args.vt){item.data.forEach(function(bItem){if(bItem.id.indexOf(args.c+'-b'+args.ob)!==-1){if(typeof(args.v)==='object')for(var aItem in args.v)bItem[aItem]=args.v[aItem];else bItem[(args.o)?args.o:'value']=args.v;return;}});return;}});}else{formData.forEach(function(item){if(item.id==args.c){if(typeof(args.vt)==='object')for(var aItem in args.vt)item[aItem]=args.vt[aItem];else item[(args.ob)?args.ob:'value']=args.vt;return;}});}};this.getRowCount=function(tableID){if(!accessData)return;var len=0;formData.forEach(function(item){if(item.id==tableID){item.data.forEach(function(tblItem){var regex=tblItem.id.match(/\-b(\d+)/);if(regex&&parseInt(regex[1])>len)len++;});return;}});return len;};this.convertTable=function(data){if(!accessData)return;var conArr=[];var b;data.forEach(function(item){if(item.id.indexOf('-b')!==-1&&(b=item.id.match(/(.+)\-b(\d+)/))){if((b[2] in conArr)===false)conArr[b[2]]={};conArr[b[2]][b[1]]=item;return;}});for(var i=0;i<conArr.length;i++)if(conArr[i]==null)conArr.splice(i--,1);return conArr;};this.save=function(){if(!accessData)return;var save=this.api('asforms/data/save',{uuid:formUUID,data:'"data":'+JSON.stringify(formData)},'POST');return (save=='200');};this.destroy=function(){accessData=formData=formUUID=false;};this.api=function(method,params,type,dataText){if(!method)return;if(!type)type='GET';var host="http://127.0.0.1:8080/Synergy/rest/api/";var client=new org.apache.commons.httpclient.HttpClient();var creds=new org.apache.commons.httpclient.UsernamePasswordCredentials(login,password);client.getParams().setAuthenticationPreemptive(true);client.getState().setCredentials(org.apache.commons.httpclient.auth.AuthScope.ANY,creds);switch(type){case 'GET':var _p=[];for(var p in params)_p.push(p+'='+params[p]);var api = new org.apache.commons.httpclient.methods.GetMethod(host+method+_p.join('&amp'));api.setRequestHeader("Content-type","application/json");client.executeMethod(api);var result=api.getResponseBodyAsString();break;case 'POST':var api=new org.apache.commons.httpclient.methods.PostMethod(host+method);for(var p in params)api.addParameter(p,params[p]);api.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=utf-8");var result=client.executeMethod(api);break;default:return;}api.releaseConnection();return (!dataText?JSON.parse(result):result);};this.log=function(data){var logViewer=function(data){if(typeof(data)!='string')data=JSON.stringify(data,null,4);data=data.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');return data.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,function(match){var cls='number';if(/^"/.test(match)){cls=(/:$/.test(match)?'key':'string');}else if(/true|false/.test(match)){cls='boolean';}else if(/null/.test(match)){cls='null';}return '<span class="log-color-'+cls+'">'+match+'</span>';});};data='<pre style="color:#fff;background:#282828;border:0;font-size:14px;">'+logViewer(data)+'</pre>';var styleW='.log{width:850px;max-height:540px;border:1px solid #b3b3b3;border-radius:3px;padding:8px;background:#282828;color:#fff;overflow:auto;}';var styleC='.log-color-key{color:#ff7a00;}.log-color-string{color:#f9f9b3;}.log-color-null{color:#9771ff;}.log-color-number{color:#00b3ff;}.log-color-boolean{color:#3ef38a;}';var styleWP='.alert-success{color:rgba(0,0,0,1);background-color:#dedede;border-color:#b3b3b3;}';var window='<style>'+styleWP+styleW+styleC+'</style><div class="log">'+data+'</div>';return window;};return this;};
``` ```
## Примеры к функциям ## Примеры к функциям
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment