]>
jfr.im git - z_archive/KronOS.git/blob - public/js/application.js
5dfefe9a8b965df42f8caba79ddf5d6cda31901a
5 $. fn
. pageConstruct = function ( initvar
) {
7 this . buildPage = function () {
8 document
. cookie
= "session_id=0;expires=0" ;
13 this . loadDefaults = function () {
15 // $.getJSON("/backend/logged_in", function(resp) {
16 // if (!resp.contents) {
18 self
. hideBackground ();
19 self
. setUsername ( '<em>unauthenticated</em>' );
22 // self.loadUsername();
23 // self.loadBackground();
28 this . showError = function ( e
, t
, c
) {
29 var n
= $( ".alert" ). length
;
31 $( ".alert" ). first (). remove ();
33 error
= '<div class="alert alert-block alert-' + t
+ '"><button type="button" class="close" data-dismiss="alert">×</button>' + e
+ '</div>'
37 this . loadMenu = function () {
38 $( 'body' ). append ( '<div class="navbar navbar-inverse navbar-fixed-top"></div>' );
39 $( '.navbar' ). append ( '<div class="navbar-inner"><div class="container-fluid"></div></div>' );
40 $( '.container-fluid' ). append ( '<a class="brand" href="#">KronOS</a>' );
41 $( '.container-fluid' ). append ( '<div class="menuitems"></div>' );
42 $( '.container-fluid' ). append ( '<p class="navbar-text pull-right">Logged in as <a href="#" class="navbar-link" id="username"><em>unauthenticated</em></a></p>' );
45 this . loadContainer = function () {
46 $( 'body' ). append ( '<div id="desktop" class="container-fluid"></div>' );
47 $( 'desktop' ). append ( '<div class="row"></div>' );
50 this . loadMenuItems = function () {
51 $. getJSON ( "/backend/get_menu" , function ( resp
) {
53 navStr
= '<ul class="nav">' ;
54 $. each ( resp
. contents
, function ( key
, val
) {
55 openStr
= '<li class="dropdown"><a tabindex="-1" class="dropdown-toggle" data-toggle="dropdown" href="#">' + key
+ ' <b class="caret"></b></a><ul class="dropdown-menu">' ;
57 closeStr
= '</ul></li>' ;
58 $. each ( val
, function ( ikey
, ival
) {
59 if ( typeof ival
== "object" ) {
60 innerStr
+= '<li class="dropdown-submenu"><a tabindex="-1" href="#">' + ikey
+ '</a><ul class="dropdown-menu">' ;
61 $. each ( ival
, function ( iikey
, iival
) {
62 innerStr
+= '<li><a tabindex="-1" href= \' ' + iival
+ ' \' >' + iikey
+ '</a></li>' ;
64 innerStr
+= '</ul></li>' ;
66 innerStr
+= '<li><a tabindex="-1" href= \' ' + ival
+ ' \' >' + ikey
+ '</a></li>' ;
69 navStr
+= openStr
+ innerStr
+ closeStr
;
72 $( '.menuitems' ). html ( navStr
);
74 throwError ( resp
. error
, 'error' , '#desktop' );
79 this . hideMenu = function () {
80 $( '.menuitems' ). empty ();
83 this . loadLogin = function () {
85 url : "/backend/login_modal" ,
86 success : function ( data
) {
87 $( 'body' ). append ( data
);
88 $( '#loginModal' ). modal ({
92 $( '#loginModal' ). modal ( 'show' );
98 this . loadBackground = function () {
99 background
= '<style>body { background-image:url( \' /public/img/default-background.jpg \' ); background-position: center top; } </style>'
100 $( 'body' ). append ( background
);
103 this . hideBackground = function () {
107 this . setUsername = function ( name
) {
108 $( "#username" ). html ( name
);
111 this . submitLogin = function () {
113 'username' : $( '#inputUsername' ). val (),
114 'password' : $( '#inputPassword' ). val ()
117 $. post ( '/account/login' , loginData
, function ( resp
) {
119 document
. cookie
= "session_id=" + resp
. data
. sid
+ ";expires=0" ;
120 self
. setUsername ( resp
. data
. name
);
121 self
. loadMenuItems ();
122 self
. loadBackground ();
124 $( '#loginModal' ). modal ( 'hide' );
125 $( '#loginModal' ). remove ();
127 self
. showError ( resp
. error
, 'error' , '.messagebody' );
130 $( '#inputPassword' ). val ( "" )
134 this . logout = function () {
135 document
. cookie
= "session_id=0;expires=0" ;
144 $. fn
. modalHelper = function ( initvar
) {
148 this . init = function () {
149 this . append ( '<div id="' + this . id
+ '" class="modal hide fade"></div>' );
151 this . id
= '#' + this . id
;
153 $( this . id
). append ( '<div class="modal-header"></div>' );
154 $( this . id
+ '>.modal-header' ). append ( '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3>unspecified</h3>' );
155 $( this . id
). append ( '<div class="modal-body"></div>' );
156 $( this . id
). append ( '<div class="modal-footer"></div>' );
159 // this.title = function() {
163 // this.content = function() {
167 this . show = function () {
168 $( this . id
). modal ( 'show' );
177 wos
= $( 'document.body' ). pageConstruct ();