]> jfr.im git - z_archive/KronOS.git/commitdiff
Added ability for apps to define javascript -- static method scripts -- not core...
authorJohn Runyon <redacted>
Sun, 3 Nov 2013 17:29:40 +0000 (17:29 +0000)
committerJohn Runyon <redacted>
Sun, 3 Nov 2013 17:29:40 +0000 (17:29 +0000)
application/controllers/control.php
application/libraries/Core.php
application/models/msession.php
kosapps/common.php
kosapps/core/credits.php
kosapps/default/users.php [new file with mode: 0644]
public/js/application.js

index 2cdf7e93c1bc27fd8328540f51fbc4127a13aff1..2a14d0b1409c96a950c1f10cd17f8acb0ad60a68 100644 (file)
@@ -32,7 +32,11 @@ class Control extends CI_Controller {
        }
 
        public function act($iid, $action) {
-//             return $this->msession->getAppInst($iid)->act($action);
+               $this->json->reply($this->msession->getAppInst($iid)->act($action));
+       }
+
+       public function scripts($aid) {
+               $this->output->set_output(call_user_func(array($this->msession->getAppClass($aid), 'scripts'), $aid));
        }
 
        public function close($iid) {
index 1c872d34327a719b8b47b0a3ac7cbb0b2fece310..23b9ecf0d359fb258c2a4aa2a7722572d987ac36 100644 (file)
@@ -21,11 +21,11 @@ class Core {
                );
 
                $ulev = $this->CI->user->level();
-               if ($ulev == 'operator') $chklevel = "a.access = 'user' OR a.access = 'operator'";
-               elseif ($ulev == 'manager') $chklevel = "1"; // full access -> always true
+               if ($ulev == 'manager') $chklevel = "1"; // full access -> always true
+               elseif ($ulev == 'operator') $chklevel = "a.access = 'user' OR a.access = 'operator'";
                else $chklevel = "a.access = 'user'"; // fallback
 
-               $sql = 'SELECT a.parent AS catid, c.catname AS category, a.appname AS appname, a.aid AS appid FROM categories AS c, apps AS a WHERE c.cid = a.parent AND ('.$chklevel.')';
+               $sql = 'SELECT a.parent AS catid, c.catname AS category, a.appname AS appname, a.aid AS appid FROM categories AS c, apps AS a WHERE a.active = 1 AND c.cid = a.parent AND ('.$chklevel.')';
                $q = $this->CI->db->query($sql);
                foreach ($q->result() as $row) {
                        if ($row->category == 'System') {
index b9b474d215c2cace4099d3bf8511faa59b2094fb..e5f2c021dbb4e69c9dd8925f4158076d05910f8e 100644 (file)
@@ -21,21 +21,39 @@ class Msession extends CI_Model {
                return $this->lastError;
        }
 
-       protected function getApp($aid, $iid, $file, $class) {
-               if (!is_file($this->config->item('app_prefix').$file)) {
-                       return $this->setError('App file does not exist');
+       protected function includeApp($file) {
+               $f = $this->config->item('app_prefix').$file;
+               if (!is_file($f)) {
+                       return $this->setError('App file does not exist '.$f);
                }
-               if (!(include_once $this->config->item('app_prefix').$file)) {
-                       return $this->setError('Include error');
+               if (!(include_once $f)) {
+                       return $this->setError('Include error '.$f);
                }
+       }
 
-               return new $class($iid);
+       protected function getApp($aid, $iid, $file, $class) {
+               $this->includeApp($file);
+               return new $class($iid, $aid);
        }
+
+       public function getAppClass($aid) {
+               $this->db->select('classname, filename');
+               $this->db->where('aid', $aid);
+               $q = $this->db->get('apps');
+               if ($q->num_rows() == 0)
+                       return FALSE;
+               $row = $q->row();
+               $filename = $row->filename;
+               $classname = $row->classname;
+               $this->includeApp($filename);
+               return $classname;
+       }
+
        public function getAppInst($iid) {
-               if ($this->apps[$iid]) {
+               if (isset($this->apps[$iid])) {
                        return $this->apps[$iid];
                } else {
-                       $this->db->select('aid');
+                       $this->db->select('aid, corename');
                        $this->db->where('iid', $iid);
                        $q = $this->db->get('session_apps');
                        if ($q->num_rows() == 0)
@@ -43,13 +61,20 @@ class Msession extends CI_Model {
                        $row = $q->row();
                        $aid = $row->aid;
 
-                       $this->db->select('classname, filename');
-                       $this->db->where('aid', $aid);
-                       $q = $this->db->get('apps');
-                       if ($q->num_rows() == 0)
-                               return FALSE;
-                       $row = $q->row();
-                       return $this->getApp($aid, $iid, $row->filename, $row->classname);
+                       if ($aid == -1) {
+                               $filename = 'core/'.$row->corename.'.php';
+                               $classname = ucfirst($row->corename);
+                       } else {
+                               $this->db->select('classname, filename');
+                               $this->db->where('aid', $aid);
+                               $q = $this->db->get('apps');
+                               if ($q->num_rows() == 0)
+                                       return FALSE;
+                               $row = $q->row();
+                               $filename = $row->filename;
+                               $classname = $row->classname;
+                       }
+                       return $this->getApp($aid, $iid, $filename, $classname);
                }
        }
 
@@ -57,6 +82,7 @@ class Msession extends CI_Model {
                $idata = array(
                        'sid' => $this->user->sid(),
                        'aid' => -1,
+                       'corename' => $name,
                );
                $this->db->insert('session_apps', $idata);
                $iid = $this->db->insert_id();
index 1720098c4a2afdc6a23d291ef826e5cd58311ae8..e72d25ef8af258a012e4b1068e9fd1b125e86f13 100644 (file)
@@ -1,21 +1,22 @@
 <?php
 
 abstract class KOS_App {
-       function __construct($iid) {
+       function __construct($iid, $aid) {
                $this->iid = $iid;
+               $this->aid = $aid;
        }
-       public function iid() {
-               return $this->iid;
-       }
+       public function iid() { return $this->iid; }
+       public function aid() { return $this->aid; }
 
        abstract public function appName();
        abstract public function windowTitle();
        abstract public function windowContents();
 
-       public function opening() { return; }
-       public function closing() { return; }
+       public function opening() { return; } // default
+       public function closing() { return; } // default
 
-       abstract public function act($action);
+       public static function scripts($aid) { return 'wos.appscripts['.$aid.'] = {load: function(t){this.target = t}};'; } // default
+       public function act($action) { return $action; } // default, but will only work for static ("content") apps.
 }
 
 ?>
index bb62584b9cbb74c3d31b80ce8f91fa65f1690063..7b8f01c951e86e0b2ba3807dcaccf7a894710bbd 100644 (file)
@@ -4,6 +4,7 @@ require_once('kosapps/common.php');
 
 class Credits extends KOS_App {
        protected $iid;
+       protected $aid;
 
        public function appName() {
                return "credits";
@@ -23,10 +24,6 @@ class Credits extends KOS_App {
 </ul>
 EOF;
        }
-
-       public function act($action) {
-               return $action;
-       }
 }
 
 ?>
diff --git a/kosapps/default/users.php b/kosapps/default/users.php
new file mode 100644 (file)
index 0000000..25a9a02
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+/*
+DOCS:
+       <script>wos.applib.loadscripts(<?php echo $this->aid() ?>);</script>
+can be used to trigger load JS from: public function scripts()
+
+scripts should return valid javascript code including at least:
+       wos.apps[<?php echo $this->aid() ?>].load = function(target){ appName.ctr = target; }
+or etc. Don't include script tags, it's loaded a la <script src="...">
+*/
+
+require_once('kosapps/common.php');
+
+class User_Manager extends KOS_App {
+       protected $iid;
+
+       public function appName() {
+               return "usermanager";
+       }
+       public function windowTitle() {
+               return "User Manager";
+       }
+       public function windowContents() {
+               return <<<EOF
+<em>User Manager!</em>
+EOF;
+       }
+
+}
+
+?>
index 92c98ad5e772acbb70924480d6be1832449030ce..4999a602b16612be2a1354a8e321ea43cb1268f5 100644 (file)
@@ -1,5 +1,5 @@
 (function( $ ) {
-       $.fn.pageConstruct = function( initvar ) {
+       $.fn.pageConstruct = function() {
 
                this.buildPage = function() {
                        document.cookie = "session_id=0;expires=0";
                                        var repl = resp.contents
                                        var target = 'div#'+repl.name+repl.id;
 
-                                       apps[repl.name] = {aid: appid, instance: repl.id, title: repl.title, target: target};
+                                       wos.apps[repl.id] = {aid: appid, instance: repl.id, title: repl.title, target: target};
+
+                                       $.getScript('control/scripts/'+appid, function() {
+                                               wos.appscripts[appid].load(target);
+                                       });
 
                                        $('body').append('<div id="'+repl.name+repl.id+'" class="app modal hide fade"></div>');
 
                        $(target).remove();
                }
 
+               this.apps = {};
+               this.appscripts = {}
+
                return this;
        };
 })( jQuery );
 
 $(function () {
-       apps = {}
        wos = $('document.body').pageConstruct();
 
        wos.buildPage();