loading....
';S.prototype={vb:function(){this.$===0&&this.Ka.show();this.$++},Hb:function(){this.$--;this.$===0&&
-this.Ka.hide("fold")}}})(window,document);
+return"URL needs to be in http://server[:port]/path format."},json:function(a){try{M(a);return null}catch(b){return b.toString()}}},function(a,b){Ba[b]=a});ja.prototype={rb:function(a,b){var c,d=a.attr("type").toLowerCase(),e=a.attr("name");if(e)e=e.split(":").pop();var f="change",g=true;if(d=="button"||d=="submit"||d=="reset"||d=="image"){c=new La(a[0],e);f="click";g=false}else if(d=="text"||d=="textarea"||d=="hidden"||d=="password"){c=new na(a[0],e);f="keyup change"}else if(d=="checkbox"){c=new oa(a[0],
+e);f="click"}else if(d=="radio"){c=new ra(a[0],e);f="click"}else if(d=="select-one")c=new pa(a[0],e);else if(d=="select-multiple")c=new qa(a[0],e);else if(d=="file")c=this.sb(a,e);else throw"Unknown type: "+d;a.data("controller",c);var h=b.get("$updateView");k(c.view,":input").bind(f,function(){if(c.e(b)){var i=k(c.view).attr("ng-action")||"";b.l(c,i)&&h(b)}return g});return c},sb:function(a){var b="__uploadWidget_"+this.Sb++,c=T.template(b);a.after(c);b=this.tb({data:this.da+"/admin/ServerAPI.swf",
+width:"95",height:"20",align:"top",wmode:"transparent"},{flashvars:"uploadWidgetId="+b,allowScriptAccess:"always"},b);a.remove();a=new T(c,a[0].name,b,this.da+"/data/"+this.ia);k(b).data("controller",a);return a}};O.flashEvent=function(a,b,c){a=y.getElementById(a);a=k(a);var d=a.data("controller");T.prototype[b].apply(d,c);_.defer(a.scope().get("$updateView"))};T.template=function(a){return k('d;--b){var q=this.children.pop().element[0];q.parentNode.removeChild(q)}if(h&&h.element[0].nodeName==="OPTION")if(d=k(h.element[0].parentNode).data("controller")){d.c=undefined;d.d(a)}})}};A.sa="mouseleave mouseout click dblclick keypress keyup";A.dc=function(){A.na();var a=k(this);a.bind(A.sa,A.na);var b=a.position(),c=y.documentElement,d=(self.innerWidth||c&&c.clientWidth||y.body.clientWidth)-b.left;c=a.hasClass("ng-exception")?"EXCEPTION:":"Validation error...";a=a.attr("ng-error");
+d=d>375?"left":"right";c=k("");k("body").append(c);if(d==="left")a=b.left+this.offsetWidth+11;else{a=b.left-315;c.find(".ng-arrow-right").css({left:301})}c.css({left:a+"px",top:b.top-3+"px"});return true};A.na=function(){k("#ng-callout").unbind(A.sa,A.na).remove();return true};A.prototype={bind:function(){this.D.find(".ng-validation-error,.ng-exception").live("mouseover",
+A.dc)}};W.Za='loading....
';W.prototype={ob:function(){this.ca===0&&this.Ha.show();this.ca++},yb:function(){this.ca--;this.ca===0&&this.Ha.hide("fold")}}})(window,document);
diff --git a/angular.js b/angular.js
index 2a8d6008..51068177 100644
--- a/angular.js
+++ b/angular.js
@@ -185,11 +185,10 @@ if (typeof Node == 'undefined') {
function noop() {}
if (!window['console']) window['console']={'log':noop, 'error':noop};
-var consoleNode,
+var consoleNode, msie,
+ jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy
foreach = _.each,
extend = _.extend,
- jQuery = window['jQuery'],
- msie = jQuery['browser']['msie'],
angular = window['angular'] || (window['angular'] = {}),
angularValidator = angular['validator'] || (angular['validator'] = {}),
angularFilter = angular['filter'] || (angular['filter'] = {}),
@@ -377,7 +376,6 @@ UrlWatcher.prototype = {
self.setTimeout(pull, self.delay);
};
pull();
- return this;
},
set: function(url) {
@@ -436,19 +434,20 @@ function exposeMethods(obj, methods){
function wireAngular(element, config) {
var widgetFactory = new WidgetFactory(config['server'], config['database']);
- var binder = new Binder(element[0], widgetFactory, config['location'], config);
- var controlBar = new ControlBar(element.find('body'), config.server);
+ var binder = new Binder(element[0], widgetFactory, datastore, config['location'], config);
+ var controlBar = new ControlBar(element.find('body'), config['server'], config['database']);
var onUpdate = function(){binder.updateView();};
- var server = config.database=="$MEMORY" ?
- new FrameServer(this.window) :
- new Server(config.server, jQuery.getScript);
+ var server = config['database'] =="$MEMORY" ?
+ new FrameServer(window) :
+ new Server(config['server'], jQuery['getScript']);
server = new VisualServer(server, new Status(jQuery(element.body)), onUpdate);
var users = new Users(server, controlBar);
- var databasePath = '/data/' + config.database;
+ var databasePath = '/data/' + config['database'];
var post = function(request, callback){
server.request("POST", databasePath, request, callback);
};
var datastore = new DataStore(post, users, binder.anchor);
+ binder.datastore = datastore;
binder.updateListeners.push(function(){datastore.flush();});
var scope = new Scope({
'$anchor' : binder.anchor,
@@ -508,10 +507,14 @@ function wireAngular(element, config) {
}
angular['startUrlWatcher'] = function(){
- return new UrlWatcher(window['location']).watch();
+ var watcher = new UrlWatcher(window['location']);
+ watcher.watch();
+ return exposeMethods(watcher, {'listen':watcher.listen, 'set':watcher.set, 'get':watcher.get});
};
angular['compile'] = function(element, config) {
+ jQuery = window['jQuery'];
+ msie = jQuery['browser']['msie'];
config = _({
'server': "",
'location': {'get':noop, 'set':noop, 'listen':noop}
@@ -842,11 +845,14 @@ defineApi('Object', [angularGlobal, angularCollection, angularObject],
['keys', 'values']);
defineApi('String', [angularGlobal, angularString], []);
defineApi('Date', [angularGlobal, angularDate], []);
+//IE bug
+angular['Date']['toString'] = angularDate['toString'];
defineApi('Function', [angularGlobal, angularCollection, angularFunction],
['bind', 'bindAll', 'delay', 'defer', 'wrap', 'compose']);
-function Binder(doc, widgetFactory, location, config) {
+function Binder(doc, widgetFactory, datastore, location, config) {
this.doc = doc;
this.location = location;
+ this.datastore = datastore;
this.anchor = {};
this.widgetFactory = widgetFactory;
this.config = config || {};
@@ -895,7 +901,7 @@ Binder.prototype = {
},
parseAnchor: function() {
- var self = this, url = this.location.get() || "";
+ var self = this, url = this.location['get']() || "";
var anchorIndex = url.indexOf('#');
if (anchorIndex < 0) return;
@@ -916,7 +922,7 @@ Binder.prototype = {
},
updateAnchor: function() {
- var url = this.location.get() || "";
+ var url = this.location['get']() || "";
var anchorIndex = url.indexOf('#');
if (anchorIndex > -1)
url = url.substring(0, anchorIndex);
@@ -933,7 +939,7 @@ Binder.prototype = {
sep = '&';
}
}
- this.location.set(url);
+ this.location['set'](url);
return url;
},
@@ -969,12 +975,14 @@ Binder.prototype = {
},
entity: function (scope) {
+ var self = this;
this.docFindWithSelf("[ng-entity]").attr("ng-watch", function() {
try {
var jNode = jQuery(this);
- var decl = scope.entity(jNode.attr("ng-entity"));
+ var decl = scope.entity(jNode.attr("ng-entity"), self.datastore);
return decl + (jNode.attr('ng-watch') || "");
} catch (e) {
+ log(e);
alert(e);
}
});
@@ -982,7 +990,7 @@ Binder.prototype = {
compile: function() {
var jNode = jQuery(this.doc);
- if (this.config.autoSubmit) {
+ if (this.config['autoSubmit']) {
var submits = this.docFindWithSelf(":submit").not("[ng-action]");
submits.attr("ng-action", "$save()");
submits.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr", '{disabled:"{{$invalidWidgets}}"}');
@@ -1192,10 +1200,11 @@ Binder.prototype = {
ng_watch: function(node, scope) {
scope.watch(node.getAttribute('ng-watch'));
}
-};function ControlBar(document, serverUrl) {
- this.document = document;
+};function ControlBar(document, serverUrl, database) {
+ this._document = document;
this.serverUrl = serverUrl;
- this.window = window;
+ this.database = database;
+ this._window = window;
this.callbacks = [];
};
@@ -1207,13 +1216,12 @@ ControlBar.HTML =
'' +
'';
+
ControlBar.FORBIDEN =
'' +
'Sorry, you do not have permission for this!'+
'
';
-
-
ControlBar.prototype = {
bind: function () {
},
@@ -1221,7 +1229,7 @@ ControlBar.prototype = {
login: function (loginSubmitFn) {
this.callbacks.push(loginSubmitFn);
if (this.callbacks.length == 1) {
- this.doTemplate("/user_session/new.mini?return_url=" + encodeURIComponent(this.urlWithoutAnchor()));
+ this.doTemplate("/user_session/new.mini?database="+encodeURIComponent(this.database)+"&return_url=" + encodeURIComponent(this.urlWithoutAnchor()));
}
},
@@ -1233,25 +1241,24 @@ ControlBar.prototype = {
},
urlWithoutAnchor: function (path) {
- return this.window.location.href.split("#")[0];
+ return this._window['location']['href'].split("#")[0];
},
doTemplate: function (path) {
var self = this;
var id = new Date().getTime();
- var url = this.urlWithoutAnchor();
- url += "#$iframe_notify=" + id;
+ var url = this.urlWithoutAnchor() + "#$iframe_notify=" + id;
var iframeHeight = 330;
var loginView = jQuery('');
- this.document.append(loginView);
- loginView.dialog({
- height:iframeHeight + 33, width:500,
- resizable: false, modal:true,
- title: 'Authentication: <angular/>'
+ this._document.append(loginView);
+ loginView['dialog']({
+ 'height':iframeHeight + 33, 'width':500,
+ 'resizable': false, 'modal':true,
+ 'title': 'Authentication: <angular/>'
});
- callbacks["_iframe_notify_" + id] = function() {
- loginView.dialog("destroy");
- loginView.remove();
+ angularCallbacks["_iframe_notify_" + id] = function() {
+ loginView['dialog']("destroy");
+ loginView['remove']();
foreach(self.callbacks, function(callback){
callback();
});
@@ -1267,7 +1274,8 @@ ControlBar.prototype = {
};function DataStore(post, users, anchor) {
this.post = post;
this.users = users;
- this._cache = {$collections:[]};
+ this._cache_collections = [];
+ this._cache = {'$collections':this._cache_collections};
this.anchor = anchor;
this.bulkRequest = [];
};
@@ -1281,10 +1289,10 @@ DataStore.NullEntity = extend(function(){}, {
DataStore.prototype = {
cache: function(document) {
- if (! document instanceof Model) {
+ if (! document.datastore === this) {
throw "Parameter must be an instance of Entity! " + toJson(document);
}
- var key = document.$entity + '/' + document.$id;
+ var key = document['$entity'] + '/' + document['$id'];
var cachedDocument = this._cache[key];
if (cachedDocument) {
Model.copyDirectFields(document, cachedDocument);
@@ -1298,10 +1306,10 @@ DataStore.prototype = {
load: function(instance, id, callback, failure) {
if (id && id !== '*') {
var self = this;
- this._jsonRequest(["GET", instance.$entity + "/" + id], function(response) {
- instance.$loadFrom(response);
- instance.$migrate();
- var clone = instance.$$entity(instance);
+ this._jsonRequest(["GET", instance['$entity'] + "/" + id], function(response) {
+ instance['$loadFrom'](response);
+ instance['$migrate']();
+ var clone = instance['$$entity'](instance);
self.cache(clone);
(callback||noop)(instance);
}, failure);
@@ -1327,8 +1335,8 @@ DataStore.prototype = {
loadOrCreate: function(instance, id, callback) {
var self=this;
return this.load(instance, id, callback, function(response){
- if (response.$status_code == 404) {
- instance.$id = id;
+ if (response['$status_code'] == 404) {
+ instance['$id'] = id;
(callback||noop)(instance);
} else {
throw response;
@@ -1339,15 +1347,15 @@ DataStore.prototype = {
loadAll: function(entity, callback) {
var self = this;
var list = [];
- list.$$accept = function(doc){
- return doc.$entity == entity.title;
+ list['$$accept'] = function(doc){
+ return doc['$entity'] == entity['title'];
};
- this._cache.$collections.push(list);
- this._jsonRequest(["GET", entity.title], function(response) {
+ this._cache_collections.push(list);
+ this._jsonRequest(["GET", entity['title']], function(response) {
var rows = response;
for ( var i = 0; i < rows.length; i++) {
var document = entity();
- document.$loadFrom(rows[i]);
+ document['$loadFrom'](rows[i]);
list.push(self.cache(document));
}
(callback||noop)(list);
@@ -1358,17 +1366,17 @@ DataStore.prototype = {
save: function(document, callback) {
var self = this;
var data = {};
- document.$saveTo(data);
+ document['$saveTo'](data);
this._jsonRequest(["POST", "", data], function(response) {
- document.$loadFrom(response);
+ document['$loadFrom'](response);
var cachedDoc = self.cache(document);
- _.each(self._cache.$collections, function(collection){
- if (collection.$$accept(document)) {
- angular['Array']['includeIf'](collection, cachedDoc, true);
+ _.each(self._cache_collections, function(collection){
+ if (collection['$$accept'](document)) {
+ angularArray['includeIf'](collection, cachedDoc, true);
}
});
- if (document.$$anchor) {
- self.anchor[document.$$anchor] = document.$id;
+ if (document['$$anchor']) {
+ self.anchor[document['$$anchor']] = document['$id'];
}
if (callback)
callback(document);
@@ -1378,13 +1386,13 @@ DataStore.prototype = {
remove: function(document, callback) {
var self = this;
var data = {};
- document.$saveTo(data);
+ document['$saveTo'](data);
this._jsonRequest(["DELETE", "", data], function(response) {
- delete self._cache[document.$entity + '/' + document.$id];
- _.each(self._cache.$collections, function(collection){
+ delete self._cache[document['$entity'] + '/' + document['$id']];
+ _.each(self._cache_collections, function(collection){
for ( var i = 0; i < collection.length; i++) {
var item = collection[i];
- if (item.$id == document.$id) {
+ if (item['$id'] == document['$id']) {
collection.splice(i, 1);
}
}
@@ -1394,8 +1402,8 @@ DataStore.prototype = {
},
_jsonRequest: function(request, callback, failure) {
- request.$$callback = callback;
- request.$$failure = failure||function(response){
+ request['$$callback'] = callback;
+ request['$$failure'] = failure||function(response){
throw response;
};
this.bulkRequest.push(request);
@@ -1409,25 +1417,25 @@ DataStore.prototype = {
log('REQUEST:', bulkRequest);
function callback(code, bulkResponse){
log('RESPONSE[' + code + ']: ', bulkResponse);
- if(bulkResponse.$status_code == 401) {
- self.users.login(function(){
+ if(bulkResponse['$status_code'] == 401) {
+ self.users['login'](function(){
self.post(bulkRequest, callback);
});
- } else if(bulkResponse.$status_code) {
+ } else if(bulkResponse['$status_code']) {
alert(toJson(bulkResponse));
} else {
for ( var i = 0; i < bulkResponse.length; i++) {
var response = bulkResponse[i];
var request = bulkRequest[i];
- var responseCode = response.$status_code;
+ var responseCode = response['$status_code'];
if(responseCode) {
if(responseCode == 403) {
- self.users.notAuthorized();
+ self.users['notAuthorized']();
} else {
- request.$$failure(response);
+ request['$$failure'](response);
}
} else {
- request.$$callback(response);
+ request['$$callback'](response);
}
}
}
@@ -1444,9 +1452,9 @@ DataStore.prototype = {
}
for(var key in scope) {
var item = scope[key];
- if (item && item.$save == Model.prototype.$save) {
+ if (item && item['$save'] == Model.prototype['$save']) {
saveCounter++;
- item.$save(onSaveDone);
+ item['$save'](onSaveDone);
}
}
onSaveDone();
@@ -1455,19 +1463,18 @@ DataStore.prototype = {
query: function(type, query, arg, callback){
var self = this;
var queryList = [];
- queryList.$$accept = function(doc){
+ queryList['$$accept'] = function(doc){
return false;
};
- this._cache.$collections.push(queryList);
- var request = type.title + '/' + query + '=' + arg;
+ this._cache_collections.push(queryList);
+ var request = type['title'] + '/' + query + '=' + arg;
this._jsonRequest(["GET", request], function(response){
var list = response;
- for(var i = 0; i < list.length; i++) {
- var document = new type().$loadFrom(list[i]);
+ foreach(list, function(item){
+ var document = type()['$loadFrom'](item);
queryList.push(self.cache(document));
- }
- if (callback)
- callback(queryList);
+ });
+ (callback||noop)(queryList);
});
return queryList;
},
@@ -1476,11 +1483,11 @@ DataStore.prototype = {
var entities = [];
var self = this;
this._jsonRequest(["GET", "$entities"], function(response) {
- for (var entityName in response) {
+ foreach(response, function(value, entityName){
entities.push(self.entity(entityName));
- }
+ });
entities.sort(function(a,b){return a.title > b.title ? 1 : -1;});
- if (callback) callback(entities);
+ (callback||noop)(entities);
});
return entities;
},
@@ -1489,9 +1496,7 @@ DataStore.prototype = {
var counts = {};
var self = this;
self.post([["GET", "$users"]], function(code, response){
- foreach(response[0], function(value, key){
- counts[key] = value;
- });
+ extend(counts, response[0]);
});
return counts;
},
@@ -1500,9 +1505,7 @@ DataStore.prototype = {
var ids = {};
var self = this;
self.post([["GET", "$users/" + user]], function(code, response){
- foreach(response[0], function(value, key){
- ids[key] = value;
- });
+ extend(ids, response[0]);
});
return ids;
},
@@ -1518,7 +1521,7 @@ DataStore.prototype = {
// entity.name does not work as name seems to be reserved for functions
'title': name,
'$$factory': true,
- 'datastore': this,
+ datastore: this, //private, obfuscate
'defaults': defaults || {},
'load': function(id, callback){
return self.load(entity(), id, callback);
@@ -1783,25 +1786,25 @@ foreach({
function(type, data, width, height) {
data = data || {};
var chart = {
- cht:type,
- chco:angularFilterGoogleChartApi.collect(data, 'color'),
- chtt:angularFilterGoogleChartApi.title(data),
- chdl:angularFilterGoogleChartApi.collect(data, 'label'),
- chd:angularFilterGoogleChartApi.values(data),
- chf:'bg,s,FFFFFF00'
+ 'cht':type,
+ 'chco':angularFilterGoogleChartApi['collect'](data, 'color'),
+ 'chtt':angularFilterGoogleChartApi['title'](data),
+ 'chdl':angularFilterGoogleChartApi['collect'](data, 'label'),
+ 'chd':angularFilterGoogleChartApi['values'](data),
+ 'chf':'bg,s,FFFFFF00'
};
- if (_.isArray(data.xLabels)) {
- chart.chxt='x';
- chart.chxl='0:|' + data.xLabels.join('|');
+ if (_.isArray(data['xLabels'])) {
+ chart['chxt']='x';
+ chart['chxl']='0:|' + data.xLabels.join('|');
}
return angularFilterGoogleChartApi['encode'](chart, width, height);
},
{
'values': function(data){
var seriesValues = [];
- foreach(data.series||[], function(serie){
+ foreach(data['series']||[], function(serie){
var values = [];
- foreach(serie.values||[], function(value){
+ foreach(serie['values']||[], function(value){
values.push(value);
});
seriesValues.push(values.join(','));
@@ -1812,7 +1815,7 @@ foreach({
'title': function(data){
var titles = [];
- var title = data.title || [];
+ var title = data['title'] || [];
foreach(_.isArray(title)?title:[title], function(text){
titles.push(encodeURIComponent(text));
});
@@ -1822,7 +1825,7 @@ foreach({
'collect': function(data, key){
var outterValues = [];
var count = 0;
- foreach(data.series||[], function(serie){
+ foreach(data['series']||[], function(serie){
var innerValues = [];
var value = serie[key] || [];
foreach(_.isArray(value)?value:[value], function(color){
@@ -1839,7 +1842,7 @@ foreach({
height = height || width;
var url = "http://chart.apis.google.com/chart?";
var urlParam = [];
- params.chs = width + "x" + height;
+ params['chs'] = width + "x" + height;
foreach(params, function(value, key){
if (value) {
urlParam.push(key + "=" + value);
@@ -1855,37 +1858,38 @@ foreach({
'qrcode': function(value, width, height) {
- return angularFilterGoogleChartApi['encode']({cht:'qr', chl:encodeURIComponent(value)}, width, height);
+ return angularFilterGoogleChartApi['encode']({
+ 'cht':'qr', 'chl':encodeURIComponent(value)}, width, height);
},
'chart': {
- pie:function(data, width, height) {
+ 'pie':function(data, width, height) {
return angularFilterGoogleChartApi('p', data, width, height);
},
- pie3d:function(data, width, height) {
+ 'pie3d':function(data, width, height) {
return angularFilterGoogleChartApi('p3', data, width, height);
},
- pieConcentric:function(data, width, height) {
+ 'pieConcentric':function(data, width, height) {
return angularFilterGoogleChartApi('pc', data, width, height);
},
- barHorizontalStacked:function(data, width, height) {
+ 'barHorizontalStacked':function(data, width, height) {
return angularFilterGoogleChartApi('bhs', data, width, height);
},
- barHorizontalGrouped:function(data, width, height) {
+ 'barHorizontalGrouped':function(data, width, height) {
return angularFilterGoogleChartApi('bhg', data, width, height);
},
- barVerticalStacked:function(data, width, height) {
+ 'barVerticalStacked':function(data, width, height) {
return angularFilterGoogleChartApi('bvs', data, width, height);
},
- barVerticalGrouped:function(data, width, height) {
+ 'barVerticalGrouped':function(data, width, height) {
return angularFilterGoogleChartApi('bvg', data, width, height);
},
- line:function(data, width, height) {
+ 'line':function(data, width, height) {
return angularFilterGoogleChartApi('lc', data, width, height);
},
- sparkline:function(data, width, height) {
+ 'sparkline':function(data, width, height) {
return angularFilterGoogleChartApi('ls', data, width, height);
},
- scatter:function(data, width, height) {
+ 'scatter':function(data, width, height) {
return angularFilterGoogleChartApi('s', data, width, height);
}
},
@@ -2027,9 +2031,9 @@ function toJsonArray(buf, obj, pretty, stack){
function Model(entity, initial) {
this['$$entity'] = entity;
- this.$loadFrom(initial||{});
- this.$entity = entity['title'];
- this.$migrate();
+ this['$loadFrom'](initial||{});
+ this['$entity'] = entity['title'];
+ this['$migrate']();
};
Model.copyDirectFields = function(src, dst) {
@@ -2049,9 +2053,9 @@ Model.copyDirectFields = function(src, dst) {
}
};
-Model.prototype = {
+extend(Model.prototype, {
'$migrate': function() {
- merge(this['$$entity'].defaults, this);
+ merge(this['$$entity']['defaults'], this);
return this;
},
@@ -2086,7 +2090,7 @@ Model.prototype = {
Model.copyDirectFields(this, other);
return this;
}
-};function Lexer(text, parsStrings){
+});function Lexer(text, parsStrings){
this.text = text;
// UTC dates have 20 characters, we send them through parser
this.dateParseLength = parsStrings ? 20 : -1;
@@ -2779,12 +2783,11 @@ Parser.prototype = {
defaults = this.primary()(null);
}
return function(self) {
- var datastore = self.scope.get('$datastore');
- var Entity = datastore.entity(entity, defaults);
+ var Entity = self.datastore.entity(entity, defaults);
self.scope.set(entity, Entity);
if (instance) {
var document = Entity();
- document.$$anchor = instance;
+ document['$$anchor'] = instance;
self.scope.set(instance, document);
return "$anchor." + instance + ":{" +
instance + "=" + entity + ".load($anchor." + instance + ");" +
@@ -2839,9 +2842,9 @@ function Scope(initialState, name) {
var State = function(){};
State.prototype = initialState;
this.state = new State();
- this.state.$parent = initialState;
+ this.state['$parent'] = initialState;
if (name == "ROOT") {
- this.state.$root = this.state;
+ this.state['$root'] = this.state;
}
};
@@ -2870,7 +2873,7 @@ Scope.getter = function(instance, path) {
}
}
}
- if (typeof instance === 'function' && !instance.$$factory) {
+ if (typeof instance === 'function' && !instance['$$factory']) {
return bind(lastInstance, instance);
}
return instance;
@@ -2902,10 +2905,12 @@ Scope.prototype = {
},
get: function(path) {
+// log('SCOPE.get', path, Scope.getter(this.state, path));
return Scope.getter(this.state, path);
},
set: function(path, value) {
+// log('SCOPE.set', path, value);
var element = path.split('.');
var instance = this.state;
for ( var i = 0; element.length > 1; i++) {
@@ -2926,6 +2931,7 @@ Scope.prototype = {
},
eval: function(expressionText, context) {
+ log('Scope.eval', expressionText);
var expression = Scope.expressionCache[expressionText];
if (!expression) {
var parser = new Parser(expressionText);
@@ -2978,13 +2984,13 @@ Scope.prototype = {
return expression(self)(self, value);
},
- entity: function(entityDeclaration) {
+ entity: function(entityDeclaration, datastore) {
var expression = new Parser(entityDeclaration).entityDeclaration();
- return expression({scope:this});
+ return expression({scope:this, datastore:datastore});
},
markInvalid: function(widget) {
- this.state.$invalidWidgets.push(widget);
+ this.state['$invalidWidgets'].push(widget);
},
watch: function(declaration) {
@@ -3042,14 +3048,13 @@ Server.prototype = {
request: function(method, url, request, callback) {
var requestId = this.uuid + (this.nextId++);
+ var payload = this.base64url(toJson({'u':url, 'm':method, 'p':request}));
+ var totalPockets = Math.ceil(payload.length / this.maxSize);
+ var baseUrl = this.url + "/$/" + requestId + "/" + totalPockets + "/";
angularCallbacks[requestId] = function(response) {
- delete angular[requestId];
+ delete angularCallbacks[requestId];
callback(200, response);
};
- var payload = {u:url, m:method, p:request};
- payload = this.base64url(toJson(payload));
- var totalPockets = Math.ceil(payload.length / this.maxSize);
- var baseUrl = this.url + "/$/" + requestId + "/" + totalPockets + "/";
for ( var pocketNo = 0; pocketNo < totalPockets; pocketNo++) {
var pocket = payload.substr(pocketNo * this.maxSize, this.maxSize);
this.getScript(baseUrl + (pocketNo+1) + "?h=" + pocket, noop);
@@ -3101,7 +3106,7 @@ function Users(server, controlBar) {
this.controlBar = controlBar;
};
-Users.prototype = {
+extend(Users.prototype, {
'fetchCurrentUser':function(callback) {
var self = this;
this.server.request("GET", "/account.json", {}, function(code, response){
@@ -3121,7 +3126,7 @@ Users.prototype = {
'login': function(callback) {
var self = this;
this.controlBar.login(function(){
- self.fetchCurrentUser(function(){
+ self['fetchCurrentUser'](function(){
(callback||noop)();
});
});
@@ -3130,7 +3135,7 @@ Users.prototype = {
'notAuthorized': function(){
this.controlBar.notAuthorized();
}
-};
+});
foreach({
'regexp': function(value, regexp, msg) {
if (!value.match(regexp)) {
@@ -3215,8 +3220,8 @@ function WidgetFactory(serverUrl, database) {
this.nextUploadId = 0;
this.serverUrl = serverUrl;
this.database = database;
- if (window.swfobject) {
- this.createSWF = swfobject.createSWF;
+ if (window['swfobject']) {
+ this.createSWF = window['swfobject']['createSWF'];
} else {
this.createSWF = function(){
alert("ERROR: swfobject not loaded!");
@@ -3275,12 +3280,12 @@ WidgetFactory.prototype = {
var view = FileController.template(uploadId);
fileInput.after(view);
var att = {
- data:this.serverUrl + "/admin/ServerAPI.swf",
- width:"95", height:"20", align:"top",
- wmode:"transparent"};
+ 'data':this.serverUrl + "/admin/ServerAPI.swf",
+ 'width':"95", 'height':"20", 'align':"top",
+ 'wmode':"transparent"};
var par = {
- flashvars:"uploadWidgetId=" + uploadId,
- allowScriptAccess:"always"};
+ 'flashvars':"uploadWidgetId=" + uploadId,
+ 'allowScriptAccess':"always"};
var swfNode = this.createSWF(att, par, uploadId);
fileInput.remove();
var cntl = new FileController(view, fileInput[0].name, swfNode, this.serverUrl + "/data/" + this.database);
@@ -3301,10 +3306,12 @@ function FileController(view, scopeName, uploader, databaseUrl) {
this.lastValue = undefined;
};
-FileController.dispatchEvent = function(id, event, args) {
+angularCallbacks['flashEvent'] = function(id, event, args) {
var object = document.getElementById(id);
- var controller = jQuery(object).data("controller");
- FileController.prototype['_on_' + event].apply(controller, args);
+ var jobject = jQuery(object);
+ var controller = jobject.data("controller");
+ FileController.prototype[event].apply(controller, args);
+ _.defer(jobject.scope().get('$updateView'));
};
FileController.template = function(id) {
@@ -3313,26 +3320,26 @@ FileController.template = function(id) {
'' +
'' +
'' +
- '');
+ '');
};
-FileController.prototype = {
- '_on_cancel': noop,
- '_on_complete': noop,
- '_on_httpStatus': function(status) {
+extend(FileController.prototype, {
+ 'cancel': noop,
+ 'complete': noop,
+ 'httpStatus': function(status) {
alert("httpStatus:" + this.scopeName + " status:" + status);
},
- '_on_ioError': function() {
+ 'ioError': function() {
alert("ioError:" + this.scopeName);
},
- '_on_open': function() {
+ 'open': function() {
alert("open:" + this.scopeName);
},
- '_on_progress':noop,
- '_on_securityError': function() {
+ 'progress':noop,
+ 'securityError': function() {
alert("securityError:" + this.scopeName);
},
- '_on_uploadCompleteData': function(data) {
+ 'uploadCompleteData': function(data) {
var value = fromJson(data);
value.url = this.attachmentsPath + '/' + value.id + '/' + value.text;
this.view.find("input").attr('checked', true);
@@ -3340,9 +3347,8 @@ FileController.prototype = {
this.value = value;
this.updateModel(scope);
this.value = null;
- scope.get('$binder').updateView();
},
- '_on_select': function(name, size, type) {
+ 'select': function(name, size, type) {
this.name = name;
this.view.find("a").text(name).attr('href', name);
this.view.find("span").text(angular['filter']['bytes'](size));
@@ -3374,10 +3380,10 @@ FileController.prototype = {
upload: function() {
if (this.name) {
- this.uploader.uploadFile(this.attachmentsPath);
+ this.uploader['uploadFile'](this.attachmentsPath);
}
}
-};
+});
///////////////////////
// NullController
@@ -3745,7 +3751,7 @@ BindAttrUpdater.prototype = {
}
var attrValue = attrValues.length ? attrValues.join('') : null;
if(isImage && attrName == 'src' && !attrValue)
- attrValue = scope.get('config.server') + '/images/blank.gif';
+ attrValue = scope.get('$config.blankImage');
jNode.attr(attrName, attrValue);
}
}
diff --git a/src/Angular.js b/src/Angular.js
index f06562da..a055ce1d 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -270,7 +270,7 @@ function exposeMethods(obj, methods){
function wireAngular(element, config) {
var widgetFactory = new WidgetFactory(config['server'], config['database']);
var binder = new Binder(element[0], widgetFactory, datastore, config['location'], config);
- var controlBar = new ControlBar(element.find('body'), config['server']);
+ var controlBar = new ControlBar(element.find('body'), config['server'], config['database']);
var onUpdate = function(){binder.updateView();};
var server = config['database'] =="$MEMORY" ?
new FrameServer(window) :
diff --git a/src/ControlBar.js b/src/ControlBar.js
index 73be74db..685beeb2 100644
--- a/src/ControlBar.js
+++ b/src/ControlBar.js
@@ -1,6 +1,7 @@
-function ControlBar(document, serverUrl) {
+function ControlBar(document, serverUrl, database) {
this._document = document;
this.serverUrl = serverUrl;
+ this.database = database;
this._window = window;
this.callbacks = [];
};
@@ -26,7 +27,7 @@ ControlBar.prototype = {
login: function (loginSubmitFn) {
this.callbacks.push(loginSubmitFn);
if (this.callbacks.length == 1) {
- this.doTemplate("/user_session/new.mini?return_url=" + encodeURIComponent(this.urlWithoutAnchor()));
+ this.doTemplate("/user_session/new.mini?database="+encodeURIComponent(this.database)+"&return_url=" + encodeURIComponent(this.urlWithoutAnchor()));
}
},
--
cgit v1.2.3