angular.js/src/ControlBar.js

72 lines
2.1 KiB
JavaScript
Raw Normal View History

2010-01-06 00:36:58 +00:00
// Copyright (C) 2008,2009 BRAT Tech LLC
2010-01-09 23:02:43 +00:00
ControlBar = function (document, serverUrl) {
2010-01-06 00:36:58 +00:00
this.document = document;
this.serverUrl = serverUrl;
this.window = window;
this.callbacks = [];
};
2010-01-09 23:02:43 +00:00
ControlBar.prototype.bind = function () {
2010-01-06 00:36:58 +00:00
};
2010-01-09 23:02:43 +00:00
ControlBar.HTML =
2010-01-06 00:36:58 +00:00
'<div>' +
'<div class="ui-widget-overlay"></div>' +
'<div id="ng-login" ng-non-bindable="true">' +
'<div class="ng-login-container"></div>' +
'</div>' +
'</div>';
2010-01-09 23:02:43 +00:00
ControlBar.prototype.login = function (loginSubmitFn) {
2010-01-06 00:36:58 +00:00
this.callbacks.push(loginSubmitFn);
if (this.callbacks.length == 1) {
this.doTemplate("/user_session/new.mini?return_url=" + encodeURIComponent(this.urlWithoutAnchor()));
}
};
2010-01-09 23:02:43 +00:00
ControlBar.prototype.logout = function (loginSubmitFn) {
2010-01-06 00:36:58 +00:00
this.callbacks.push(loginSubmitFn);
if (this.callbacks.length == 1) {
this.doTemplate("/user_session/do_destroy.mini");
}
};
2010-01-09 23:02:43 +00:00
ControlBar.prototype.urlWithoutAnchor = function (path) {
2010-01-06 00:36:58 +00:00
return this.window.location.href.split("#")[0];
};
2010-01-09 23:02:43 +00:00
ControlBar.prototype.doTemplate = function (path) {
2010-01-06 00:36:58 +00:00
var self = this;
var id = new Date().getTime();
var url = this.urlWithoutAnchor();
url += "#$iframe_notify=" + id;
var iframeHeight = 330;
var loginView = jQuery('<div style="overflow:hidden; padding:2px 0 0 0;"><iframe name="'+ url +'" src="'+this.serverUrl + path + '" width="500" height="'+ iframeHeight +'"/></div>');
this.document.append(loginView);
loginView.dialog({
height:iframeHeight + 33, width:500,
resizable: false, modal:true,
title: 'Authentication: <a href="http://www.getangular.com"><tt>&lt;angular/&gt;</tt></a>'
});
2010-01-09 23:02:43 +00:00
callbacks["_iframe_notify_" + id] = function() {
2010-01-06 00:36:58 +00:00
loginView.dialog("destroy");
loginView.remove();
2010-01-12 00:15:12 +00:00
foreach(self.callbacks, function(callback){
2010-01-06 00:36:58 +00:00
callback();
});
self.callbacks = [];
};
};
2010-01-09 23:02:43 +00:00
ControlBar.FORBIDEN =
2010-01-06 00:36:58 +00:00
'<div ng-non-bindable="true" title="Permission Error:">' +
'Sorry, you do not have permission for this!'+
'</div>';
2010-01-09 23:02:43 +00:00
ControlBar.prototype.notAuthorized = function () {
2010-01-06 00:36:58 +00:00
if (this.forbidenView) return;
2010-01-09 23:02:43 +00:00
this.forbidenView = jQuery(ControlBar.FORBIDEN);
2010-01-06 00:36:58 +00:00
this.forbidenView.dialog({bgiframe:true, height:70, modal:true});
};