function ControlBar(document, serverUrl, database) {
this._document = document;
this.serverUrl = serverUrl;
this.database = database;
this._window = window;
this.callbacks = [];
};
ControlBar.HTML =
'
';
ControlBar.FORBIDEN =
'' +
'Sorry, you do not have permission for this!'+
'
';
ControlBar.prototype = {
bind: function () {
},
login: function (loginSubmitFn) {
this.callbacks.push(loginSubmitFn);
if (this.callbacks.length == 1) {
this.doTemplate("/user_session/new.mini?database="+encodeURIComponent(this.database)+"&return_url=" + encodeURIComponent(this.urlWithoutAnchor()));
}
},
logout: function (loginSubmitFn) {
this.callbacks.push(loginSubmitFn);
if (this.callbacks.length == 1) {
this.doTemplate("/user_session/do_destroy.mini");
}
},
urlWithoutAnchor: function (path) {
return this._window['location']['href'].split("#")[0];
},
doTemplate: function (path) {
var self = this;
var id = new Date().getTime();
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/>'
});
angularCallbacks["_iframe_notify_" + id] = function() {
loginView['dialog']("destroy");
loginView['remove']();
foreach(self.callbacks, function(callback){
callback();
});
self.callbacks = [];
};
},
notAuthorized: function () {
if (this.forbidenView) return;
this.forbidenView = jQuery(ControlBar.FORBIDEN);
this.forbidenView.dialog({bgiframe:true, height:70, modal:true});
}
};