1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
function ControlBar(document, serverUrl, database) {
this._document = document;
this.serverUrl = serverUrl;
this.database = database;
this._window = window;
this.callbacks = [];
};
ControlBar.HTML =
'<div>' +
'<div class="ui-widget-overlay"></div>' +
'<div id="ng-login" ng-non-bindable="true">' +
'<div class="ng-login-container"></div>' +
'</div>' +
'</div>';
ControlBar.FORBIDEN =
'<div ng-non-bindable="true" title="Permission Error:">' +
'Sorry, you do not have permission for this!'+
'</div>';
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('<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><angular/></tt></a>'
});
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});
}
};
|