]> git.proxmox.com Git - sencha-touch.git/blob - src/src/platform/src/data/sync/Utilities.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / src / platform / src / data / sync / Utilities.js
1
2 Ext.data.utilities= {
3
4 delegate: function(from_instance, to_instance, methods) {
5 if (to_instance===undefined) { throw "Error - Tried to delegate '"+methods+"' to undefined instance."; }
6 methods.forEach(function(method){
7 var to_method= to_instance[method];
8 if (to_method===undefined) { throw "Error - Tried to delegate undefined method '"+method+"' to "+to_instance; }
9 from_instance[method]= function() {
10 return to_method.apply(to_instance, arguments);
11 };
12 });
13 },
14
15 apply: function(instance,methods,a,done_callback,done_scope) {
16 var first= true;
17 Ext.data.array.forEachAsync(methods,function(method,next_callback,next_scope){
18 if (first) {
19 a.push(next_callback);
20 a.push(next_scope);
21 first= false;
22 }
23 instance[method].apply(instance,a);
24 },instance,done_callback,done_scope);
25 },
26
27 copy: function(from_instance,to_instance,properties) {
28 var changed= false;
29 properties.forEach(function(property){
30 var from_v= from_instance[property];
31 var to_v= to_instance[property];
32 if (from_v!==undefined && from_v!==to_v) {
33 to_instance[property]= from_v;
34 changed= true;
35 }
36 });
37 return changed;
38 },
39
40 copyIfUndefined: function(from_instance,to_instance,properties) {
41 var changed= false;
42 properties.forEach(function(property){
43 var from_v= from_instance[property];
44 var to_v= to_instance[property];
45 if (from_v!==undefined && to_v===undefined) {
46 to_instance[property]= from_v;
47 changed= true;
48 }
49 });
50 return changed;
51 },
52
53 check: function(class_name, method_name, instance_name, instance, properties) {
54 if (instance===undefined) {
55 var message= "Error - "+class_name+"."+method_name+" - "+instance_name+" not provided.";
56 console.log(message);
57 throw message;
58 } else {
59 properties.forEach(function(property) {
60 var value= instance[property];
61 if (value===undefined) {
62 var message= "Error - "+class_name+"."+method_name+" - "+instance_name+"."+property+" not provided.";
63 console.log(message);
64 throw message;
65 }
66 });
67 }
68 },
69
70 minus: function(a,b) { // minus(a,b) is all the name value pairs in a that are not in b
71 var n, r= {};
72 for(n in a) {
73 if (a.hasOwnProperty(n)) {
74 if (b[n]===undefined) {
75 r[n]= a[n];
76 }
77 }
78 }
79 return r;
80 },
81
82 intersection: function(a,b) {
83 var n, r= {};
84 for(n in a) {
85 if (a.hasOwnProperty(n)) {
86 if (b[n]!==undefined) {
87 r[n]= a[n];
88 }
89 }
90 }
91 return r;
92 }
93 };
94