1- // Copyright (C) 2008,2009 BRAT Tech LLC
2-
3- ControlBar = function ( document , serverUrl ) {
1+ function ControlBar ( document , serverUrl ) {
42 this . document = document ;
53 this . serverUrl = serverUrl ;
64 this . window = window ;
75 this . callbacks = [ ] ;
86} ;
97
10- ControlBar . prototype . bind = function ( ) {
11- } ;
12-
138ControlBar . HTML =
149 '<div>' +
1510 '<div class="ui-widget-overlay"></div>' +
@@ -18,54 +13,61 @@ ControlBar.HTML =
1813 '</div>' +
1914 '</div>' ;
2015
21- ControlBar . prototype . login = function ( loginSubmitFn ) {
22- this . callbacks . push ( loginSubmitFn ) ;
23- if ( this . callbacks . length == 1 ) {
24- this . doTemplate ( "/user_session/new.mini?return_url=" + encodeURIComponent ( this . urlWithoutAnchor ( ) ) ) ;
25- }
26- } ;
27-
28- ControlBar . prototype . logout = function ( loginSubmitFn ) {
29- this . callbacks . push ( loginSubmitFn ) ;
30- if ( this . callbacks . length == 1 ) {
31- this . doTemplate ( "/user_session/do_destroy.mini" ) ;
32- }
33- } ;
34-
35- ControlBar . prototype . urlWithoutAnchor = function ( path ) {
36- return this . window . location . href . split ( "#" ) [ 0 ] ;
37- } ;
38-
39- ControlBar . prototype . doTemplate = function ( path ) {
40- var self = this ;
41- var id = new Date ( ) . getTime ( ) ;
42- var url = this . urlWithoutAnchor ( ) ;
43- url += "#$iframe_notify=" + id ;
44- var iframeHeight = 330 ;
45- var loginView = jQuery ( '<div style="overflow:hidden; padding:2px 0 0 0;"><iframe name="' + url + '" src="' + this . serverUrl + path + '" width="500" height="' + iframeHeight + '"/></div>' ) ;
46- this . document . append ( loginView ) ;
47- loginView . dialog ( {
48- height :iframeHeight + 33 , width :500 ,
49- resizable : false , modal :true ,
50- title : 'Authentication: <a href="http://www.getangular.com"><tt><angular/></tt></a>'
51- } ) ;
52- callbacks [ "_iframe_notify_" + id ] = function ( ) {
53- loginView . dialog ( "destroy" ) ;
54- loginView . remove ( ) ;
55- foreach ( self . callbacks , function ( callback ) {
56- callback ( ) ;
57- } ) ;
58- self . callbacks = [ ] ;
59- } ;
60- } ;
61-
6216ControlBar . FORBIDEN =
6317 '<div ng-non-bindable="true" title="Permission Error:">' +
6418 'Sorry, you do not have permission for this!' +
6519 '</div>' ;
6620
67- ControlBar . prototype . notAuthorized = function ( ) {
68- if ( this . forbidenView ) return ;
69- this . forbidenView = jQuery ( ControlBar . FORBIDEN ) ;
70- this . forbidenView . dialog ( { bgiframe :true , height :70 , modal :true } ) ;
71- } ;
21+
22+
23+ ControlBar . prototype = {
24+ bind : function ( ) {
25+ } ,
26+
27+ login : function ( loginSubmitFn ) {
28+ this . callbacks . push ( loginSubmitFn ) ;
29+ if ( this . callbacks . length == 1 ) {
30+ this . doTemplate ( "/user_session/new.mini?return_url=" + encodeURIComponent ( this . urlWithoutAnchor ( ) ) ) ;
31+ }
32+ } ,
33+
34+ logout : function ( loginSubmitFn ) {
35+ this . callbacks . push ( loginSubmitFn ) ;
36+ if ( this . callbacks . length == 1 ) {
37+ this . doTemplate ( "/user_session/do_destroy.mini" ) ;
38+ }
39+ } ,
40+
41+ urlWithoutAnchor : function ( path ) {
42+ return this . window . location . href . split ( "#" ) [ 0 ] ;
43+ } ,
44+
45+ doTemplate : function ( path ) {
46+ var self = this ;
47+ var id = new Date ( ) . getTime ( ) ;
48+ var url = this . urlWithoutAnchor ( ) ;
49+ url += "#$iframe_notify=" + id ;
50+ var iframeHeight = 330 ;
51+ var loginView = jQuery ( '<div style="overflow:hidden; padding:2px 0 0 0;"><iframe name="' + url + '" src="' + this . serverUrl + path + '" width="500" height="' + iframeHeight + '"/></div>' ) ;
52+ this . document . append ( loginView ) ;
53+ loginView . dialog ( {
54+ height :iframeHeight + 33 , width :500 ,
55+ resizable : false , modal :true ,
56+ title : 'Authentication: <a href="http://www.getangular.com"><tt><angular/></tt></a>'
57+ } ) ;
58+ callbacks [ "_iframe_notify_" + id ] = function ( ) {
59+ loginView . dialog ( "destroy" ) ;
60+ loginView . remove ( ) ;
61+ foreach ( self . callbacks , function ( callback ) {
62+ callback ( ) ;
63+ } ) ;
64+ self . callbacks = [ ] ;
65+ } ;
66+ } ,
67+
68+ notAuthorized : function ( ) {
69+ if ( this . forbidenView ) return ;
70+ this . forbidenView = jQuery ( ControlBar . FORBIDEN ) ;
71+ this . forbidenView . dialog ( { bgiframe :true , height :70 , modal :true } ) ;
72+ }
73+ } ;
0 commit comments