--- /dev/null
+<html>\r
+<head>\r
+ <title>The source code</title>\r
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
+</head>\r
+<body onload="prettyPrint();">\r
+ <pre class="prettyprint lang-js">Ext.sql.Proxy = function(conn, table, keyName, store, readonly){\r
+ Ext.sql.Proxy.superclass.constructor.call(this);\r
+ this.conn = conn;\r
+ this.table = this.conn.getTable(table, keyName);\r
+ this.store = store;\r
+\r
+ if (readonly !== true) {\r
+ this.store.on('add', this.onAdd, this);\r
+ this.store.on('update', this.onUpdate, this);\r
+ this.store.on('remove', this.onRemove, this);\r
+ }\r
+};\r
+\r
+Ext.sql.Proxy.DATE_FORMAT = 'Y-m-d H:i:s';\r
+\r
+Ext.extend(Ext.sql.Proxy, Ext.data.DataProxy, {\r
+ load : function(params, reader, callback, scope, arg){\r
+ if(!this.conn.isOpen()){ // assume that the connection is in the process of opening\r
+ this.conn.on('open', function(){\r
+ this.load(params, reader, callback, scope, arg);\r
+ }, this, {single:true});\r
+ return;\r
+ };\r
+ if(this.fireEvent("beforeload", this, params, reader, callback, scope, arg) !== false){\r
+ var clause = params.where || '';\r
+ var args = params.args || [];\r
+ var group = params.groupBy;\r
+ var sort = params.sort;\r
+ var dir = params.dir;\r
+\r
+ if(group || sort){\r
+ clause += ' ORDER BY ';\r
+ if(group && group != sort){\r
+ clause += group + ' ASC, ';\r
+ }\r
+ clause += sort + ' ' + (dir || 'ASC');\r
+ }\r
+\r
+ var rs = this.table.selectBy(clause, args);\r
+ this.onLoad({callback:callback, scope:scope, arg:arg, reader: reader}, rs);\r
+ }else{\r
+ callback.call(scope||this, null, arg, false);\r
+ }\r
+ },\r
+\r
+ onLoad : function(trans, rs, e, stmt){\r
+ if(rs === false){\r
+ this.fireEvent("loadexception", this, null, trans.arg, e);\r
+ trans.callback.call(trans.scope||window, null, trans.arg, false);\r
+ return;\r
+ }\r
+ var result = trans.reader.readRecords(rs);\r
+ this.fireEvent("load", this, rs, trans.arg);\r
+ trans.callback.call(trans.scope||window, result, trans.arg, true);\r
+ },\r
+\r
+ processData : function(o){\r
+ var fs = this.store.fields;\r
+ var r = {};\r
+ for(var key in o){\r
+ var f = fs.key(key), v = o[key];\r
+ if(f){\r
+ if(f.type == 'date'){\r
+ r[key] = v ? v.format(Ext.sql.Proxy.DATE_FORMAT,10) : '';\r
+ }else if(f.type == 'boolean'){\r
+ r[key] = v ? 1 : 0;\r
+ }else{\r
+ r[key] = v;\r
+ }\r
+ }\r
+ }\r
+ return r;\r
+ },\r
+\r
+ onUpdate : function(ds, record){\r
+ var changes = record.getChanges();\r
+ var kn = this.table.keyName;\r
+ this.table.updateBy(this.processData(changes), kn + ' = ?', [record.data[kn]]);\r
+ record.commit(true);\r
+ },\r
+\r
+ onAdd : function(ds, records, index){\r
+ for(var i = 0, len = records.length; i < len; i++){\r
+ this.table.insert(this.processData(records[i].data));\r
+ }\r
+ },\r
+\r
+ onRemove : function(ds, record, index){\r
+ var kn = this.table.keyName;\r
+ this.table.removeBy(kn + ' = ?', [record.data[kn]]);\r
+ }\r
+});</pre> \r
+</body>\r
+</html>
\ No newline at end of file