cherryext/orun/extjs/static/ext-6.2.0/packages/legacy/classic/legacy.js

1 line
6.6 KiB
JavaScript
Raw Permalink Normal View History

2018-08-17 12:14:11 +03:00
Ext.define("Ext.data.proxy.Sql",{alias:"proxy.sql",extend:"Ext.data.proxy.Client",alternateClassName:"Ext.data.proxy.SQL",isSQLProxy:true,config:{reader:null,writer:null,table:null,database:"Sencha"},_createOptions:{silent:true,dirty:false},updateModel:function(c){var g=this,b,a,e,d,f;if(c){g.uniqueIdStrategy=c.identifier.isUnique;if(!g.getTable()){b=c.entityName;g.setTable(b.slice(b.lastIndexOf(".")+1))}g.columns=d=g.getPersistedModelColumns(c);g.quotedColumns=f=[];for(e=0,a=d.length;e<a;++e){f.push('"'+d[e]+'"')}}g.callParent([c])},setException:function(a,b){a.setException(b)},create:function(c){var e=this,b=c.getRecords(),a,d;c.setStarted();e.executeTransaction(function(f){e.insertRecords(b,f,function(h,g){a=h;d=g})},function(f){c.setException(f)},function(){if(d){c.setException(statementError)}else{c.process(a)}})},read:function(d){var g=this,e=g.getModel(),b=d.getRecords(),f=b?b[0]:null,i,h,a,c;if(f&&!f.phantom){a=f.getId()}else{a=d.getId()}if(a!==undefined){c={idOnly:true,id:a}}else{c={page:d.getPage(),start:d.getStart(),limit:d.getLimit(),sorters:d.getSorters(),filters:d.getFilters()}}d.setStarted();g.executeTransaction(function(j){g.selectRecords(j,c,function(l,k){i=l;h=k})},function(j){d.setException(j)},function(){if(h){d.setException(statementError)}else{d.process(i)}})},update:function(c){var e=this,b=c.getRecords(),a,d;c.setStarted();e.executeTransaction(function(f){e.updateRecords(f,b,function(h,g){a=h;d=g})},function(f){c.setException(f)},function(){if(d){c.setException(statementError)}else{c.process(a)}})},erase:function(c){var e=this,b=c.getRecords(),a,d;c.setStarted();e.executeTransaction(function(f){e.destroyRecords(f,b,function(h,g){a=h;d=g})},function(f){c.setException(f)},function(){if(d){c.setException(d)}else{c.process(a)}})},createTable:function(b){var a=this;if(!b){a.executeTransaction(function(c){a.createTable(c)});return}a.executeStatement(b,'CREATE TABLE IF NOT EXISTS "'+a.getTable()+'" ('+a.getSchemaString()+")",function(){a.tableExists=true})},insertRecords:function(k,l,d){var q=this,a=q.columns,h=k.length,s=0,p=q.uniqueIdStrategy,o=q._createOptions,n=k.length,j,c,e,m,r,b,f,g;g=function(i){++s;if(s===h){d.call(q,new Ext.data.ResultSet({success:!f}),f)}};e=Ext.String.repeat("?",a.length,",");m='INSERT INTO "'+q.getTable()+'" ('+q.quotedColumns.join(",")+") VALUES ("+e+")";for(j=0;j<n;++j){c=k[j];r=q.getRecordData(c);b=q.getColumnValues(a,r);(function(i){q.executeStatement(l,m,b,function(u,t){if(!p){i.setId(t.insertId,o)}g()},function(u,t){if(!f){f=[]}f.push(t);g()})})(c)}},selectRecords:function(s,v,e,c){var w=this,l=w.getModel(),j=l.idProperty,t='SELECT * FROM "'+w.getTable()+'"',a=" WHERE ",o=" ORDER BY ",d=[],b,k,f,r,u,n,m,q,g,h,p;if(v.idOnly){t+=a+'"'+j+'" = ?';d.push(v)}else{k=v.filters;u=k&&k.length;if(u){for(r=0;r<u;r++){m=k[r];g=m.getProperty();p=w.toSqlValue(m.getValue(),l.getField(g));h=m.getOperator();if(g!==null){h=h||"=";f="?";if(h==="like"||(h==="="&&m.getAnyMatch())){h="LIKE";p="%"+p+"%"}if(h==="in"||h==="notin"){if(h==="notin"){h="not in"}f="("+Ext.String.repeat("?",p.length,",")+")";d=d.concat(p)}else{d.push(p)}t+=a+'"'+g+'" '+h+" "+f;a=" AND "}}}b=v.sorters;u=b&&b.length;if(u){for(r=0;r<u;r++){q=b[r];g=q.getProperty();if(g!==null){t+=o+'"'+g+'" '+q.getDirection();o=", "}}}if(v.page!==undefined){t+=" LIMIT "+parseInt(v.start,10)+", "+parseInt(v.limit,10)}}w.executeStatement(s,t,d,function(z,I){var K=I.rows,G=K.length,A=[],E=l.fields,y=E.length,J,D,C,F,B,H,x;for(C=0,F=G;C<F;++C){J=K.item(C);D={};for(B=0;B<y;++B){H=E[B];x=H.name;D[x]=w.fromSqlValue(J[x],H)}A.push(new l(D))}e.call(w,new Ext.data.ResultSet({records:A,success:true,total:G,count:G}))},function(x,i){e.call(w,new Ext.data.ResultSet({success:false,total:0,count:0}),i)})},updateRecords:function(n,m,d){var r=this,a=r.columns,j=r.quotedColumns,k=m.length,t=0,g=[],q=r._createOptions,p,l,c,e,o,s,b,f,h;h=function(i){++t;if(t===k){d.call(r,new Ext.data.ResultSet({success:!f}),f)}};for(l=0,p=j.length;l<p;l++){g.push(j[l]+" = ?")}o='UPDATE "'+r.getTable()+'" SET '+g.join(", ")+' WHERE "'+r.getModel().idProperty+'" = ?';for(l