passwd input in admin subapp
[outofuni/stafforg.git] / app / www / js / index.js
index 98eaa9f..446c060 100644 (file)
@@ -34,15 +34,22 @@ var stafforg = {
        },
        startup: function() {
                cl("starting stafforg app ...");
        },
        startup: function() {
                cl("starting stafforg app ...");
-               // ui
+
+               // idb
+               var stores={
+                       'admin': db_admin_store
+               }
+               idb.init('stafforg',stafforg.dbcb,1,stores);
+
+               // ui will be initialized in db callback
+       },
+       dbcb: function() {
                stafforg.activate_subapp('start');
                $('.startbtn').click(function(event) {
                stafforg.activate_subapp('start');
                $('.startbtn').click(function(event) {
-                       cl("clicked "+event.target.id);
-                       stafforg.event_action(event,'start');
+                       var sapp=event.target.id.replace(/^sel/,'');
+                       cl("clicked "+event.target.id+", starting "+sapp);
+                       stafforg.event_action(sapp,'start');
                });
                });
-               // db
-       },
-       dbcb: function() {
        },
        activate_subapp: function(sapp) {
                $('.startbtn').each(function() {
        },
        activate_subapp: function(sapp) {
                $('.startbtn').each(function() {
@@ -55,12 +62,68 @@ var stafforg = {
                                $(sappid).css('display','none');
                });
                if(sapp=='start') {
                                $(sappid).css('display','none');
                });
                if(sapp=='start') {
-                       var sappid='#'+sapp;
-                       $(sappid).css('height','100%');
-                       $(sappid).css('display','block');
+                       $('#start').css('height','100%');
+                       $('#start').css('display','block');
+               }
+               else {
+                       $('#start').css('display','none');
+               }
+               vert_align_text('.head');
+               switch(sapp) {
+               case 'admin':
+                       stafforg.admin_init();
+                       break;
+               }
+       },
+       event_action: function(sapp,type) {
+               switch(type) {
+               case 'start':
+                       stafforg.activate_subapp(sapp);
+                       break;
                }
        },
                }
        },
-       event_action: function() {
+       admin_init: function() {
+               idb.get_item_by_key('admin',1,function(item) {
+                       if(item.passwd==undefined) {
+                               $('#adminset').css('display','block');
+                               $('#adminauth').css('display','none');
+                               $('#adminmain').css('display','none');
+                               $('#adminpw1').keyup(function() {
+                                       stafforg.checkpw();
+                               });
+                               $('#adminpw2').keyup(function() {
+                                       stafforg.checkpw();
+                               });
+                       }
+                       else {
+                       }
+               });
+       },
+       checkpw: function() {
+               var pw1=$('#adminpw1').val();
+               var pw2=$('#adminpw2').val();
+
+               if(pw1=='') {
+                       $('#adminpw1').css('border-color','red');
+                       return
+               }
+               else {
+                       $('#adminpw1').css('border-color','black');
+               }
+
+               if(pw2=='') {
+                       $('#adminpw2').css('border-color','grey');
+                       return
+               }
+
+               if(pw1!=pw2) {
+                       $('#adminpw2').css('border-color','red');
+                       return
+               }
+
+               if(pw1==pw2) {
+                       alert("yep, i will store this password!");
+               }
        }
 };
 
        }
 };