22 _SOURCE_STATUS_EMPTY : 0, |
22 _SOURCE_STATUS_EMPTY : 0, |
23 _SOURCE_STATUS_WAITING : 1, |
23 _SOURCE_STATUS_WAITING : 1, |
24 _SOURCE_STATUS_READY : 2, |
24 _SOURCE_STATUS_READY : 2, |
25 getUID : function() { |
25 getUID : function() { |
26 return uidbase + pad(4, (++uidincrement % 0x10000), 16) + "-" + rand16(4) + "-" + rand16(6) + rand16(6); |
26 return uidbase + pad(4, (++uidincrement % 0x10000), 16) + "-" + rand16(4) + "-" + rand16(6) + rand16(6); |
|
27 }, |
|
28 isLocalURL : function(url) { |
|
29 var matches = url.match(/^(\w+:)\/\/([^/]+)/); |
|
30 if (matches) { |
|
31 return(matches[1] === document.location.protocol && matches[2] === document.location.host) |
|
32 } |
|
33 return true; |
27 }, |
34 }, |
28 regexpFromTextOrArray : function(_textOrArray, _testOnly, _iexact) { |
35 regexpFromTextOrArray : function(_textOrArray, _testOnly, _iexact) { |
29 var _testOnly = _testOnly || false, |
36 var _testOnly = _testOnly || false, |
30 _iexact = _iexact || false; |
37 _iexact = _iexact || false; |
31 function escapeText(_text) { |
38 function escapeText(_text) { |
1055 |
1062 |
1056 Model.RemoteSource.prototype = new Model.Source(); |
1063 Model.RemoteSource.prototype = new Model.Source(); |
1057 |
1064 |
1058 Model.RemoteSource.prototype.get = function() { |
1065 Model.RemoteSource.prototype.get = function() { |
1059 this.status = Model._SOURCE_STATUS_WAITING; |
1066 this.status = Model._SOURCE_STATUS_WAITING; |
1060 var _this = this; |
1067 var _this = this, |
1061 this.serializer.loadData(this.url, function(_result) { |
1068 urlparams = this.url_params || {}, |
1062 _this.deSerialize(_result); |
1069 dataType = (Model.isLocalURL(this.url) ? "json" : "jsonp"); |
1063 _this.handleCallbacks(); |
1070 urlparams.format = dataType; |
|
1071 ns.jQuery.ajax({ |
|
1072 url: this.url, |
|
1073 dataType: dataType, |
|
1074 data: urlparams, |
|
1075 success: function(_result) { |
|
1076 _this.deSerialize(_result); |
|
1077 _this.handleCallbacks(); |
|
1078 } |
1064 }); |
1079 }); |
1065 } |
1080 } |
1066 |
1081 |
1067 /* */ |
1082 /* */ |
1068 |
1083 |
1074 Model.Directory.prototype.remoteSource = function(_properties) { |
1089 Model.Directory.prototype.remoteSource = function(_properties) { |
1075 if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
1090 if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
1076 throw "Error : Model.Directory.remoteSource(configuration): configuration.url is undefined"; |
1091 throw "Error : Model.Directory.remoteSource(configuration): configuration.url is undefined"; |
1077 } |
1092 } |
1078 var _config = ns._({ directory: this }).extend(_properties); |
1093 var _config = ns._({ directory: this }).extend(_properties); |
1079 if (typeof this.remoteSources[_properties.url] === "undefined") { |
1094 _config.url_params = _config.url_params || {}; |
1080 this.remoteSources[_properties.url] = new Model.RemoteSource(_config); |
1095 var _hash = _config.url + "?" + ns.jQuery.param(_config.url_params); |
1081 } |
1096 if (typeof this.remoteSources[_hash] === "undefined") { |
1082 return this.remoteSources[_properties.url]; |
1097 this.remoteSources[_hash] = new Model.RemoteSource(_config); |
|
1098 } |
|
1099 return this.remoteSources[_hash]; |
1083 } |
1100 } |
1084 |
1101 |
1085 Model.Directory.prototype.newLocalSource = function(_properties) { |
1102 Model.Directory.prototype.newLocalSource = function(_properties) { |
1086 var _config = ns._({ directory: this }).extend(_properties), |
1103 var _config = ns._({ directory: this }).extend(_properties), |
1087 _res = new Model.Source(_config); |
1104 _res = new Model.Source(_config); |