From: John Runyon Date: Sun, 3 Nov 2013 17:29:40 +0000 (+0000) Subject: Added ability for apps to define javascript -- static method scripts -- not core... X-Git-Url: https://jfr.im/git/z_archive/KronOS.git/commitdiff_plain/906f0f923329bc442b1d91bf5ec0e3800e09ac46 Added ability for apps to define javascript -- static method scripts -- not core apps --- diff --git a/application/controllers/control.php b/application/controllers/control.php index 2cdf7e9..2a14d0b 100644 --- a/application/controllers/control.php +++ b/application/controllers/control.php @@ -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) { diff --git a/application/libraries/Core.php b/application/libraries/Core.php index 1c872d3..23b9ecf 100644 --- a/application/libraries/Core.php +++ b/application/libraries/Core.php @@ -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') { diff --git a/application/models/msession.php b/application/models/msession.php index b9b474d..e5f2c02 100644 --- a/application/models/msession.php +++ b/application/models/msession.php @@ -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(); diff --git a/kosapps/common.php b/kosapps/common.php index 1720098..e72d25e 100644 --- a/kosapps/common.php +++ b/kosapps/common.php @@ -1,21 +1,22 @@ 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. } ?> diff --git a/kosapps/core/credits.php b/kosapps/core/credits.php index bb62584..7b8f01c 100644 --- a/kosapps/core/credits.php +++ b/kosapps/core/credits.php @@ -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 { EOF; } - - public function act($action) { - return $action; - } } ?> diff --git a/kosapps/default/users.php b/kosapps/default/users.php new file mode 100644 index 0000000..25a9a02 --- /dev/null +++ b/kosapps/default/users.php @@ -0,0 +1,32 @@ +wos.applib.loadscripts(aid() ?>); +can be used to trigger load JS from: public function scripts() + +scripts should return valid javascript code including at least: + wos.apps[aid() ?>].load = function(target){ appName.ctr = target; } +or etc. Don't include script tags, it's loaded a la