updated system state system into a working prototype
This commit is contained in:
parent
d3ffdf713d
commit
058d4d3b90
@ -12,12 +12,8 @@ class api_system extends api_login{
|
||||
public static function call_files($cat,$id = null){
|
||||
return \SYSTEM\FILES\files::get($cat, $id, true);}
|
||||
|
||||
public static function call_pagestates($group){
|
||||
public static function call_pages($group){
|
||||
return \SYSTEM\PAGE\State::get($group);}
|
||||
public static function call_pagestates_flag_js($group){
|
||||
return \SYSTEM\PAGE\State::get_js($group);}
|
||||
public static function call_pagestates_flag_css($group){
|
||||
return \SYSTEM\PAGE\State::get_css($group);}
|
||||
|
||||
public static function static__lang($lang){
|
||||
\SYSTEM\locale::set($lang);}
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
namespace SYSTEM\DBD;
|
||||
|
||||
class SYS_PAGESTATES_GROUP extends \SYSTEM\DB\QP {
|
||||
protected static function query(){
|
||||
return new \SYSTEM\DB\QQuery(get_class(),
|
||||
//pg
|
||||
'SELECT * FROM '.\SYSTEM\DBD\system_pagestates::NAME_PG
|
||||
.' WHERE "'.\SYSTEM\DBD\system_pagestates::FIELD_GROUP.'" = $1'
|
||||
.' ORDER BY "'.\SYSTEM\DBD\system_pagestates::FIELD_ID.'"',
|
||||
//mys
|
||||
'SELECT * FROM '.\SYSTEM\DBD\system_pagestates::NAME_MYS
|
||||
.' WHERE `'.\SYSTEM\DBD\system_pagestates::FIELD_GROUP.'` = ?'
|
||||
.' ORDER BY '.\SYSTEM\DBD\system_pagestates::FIELD_ID
|
||||
);}}
|
||||
15
dbd/qq/SYS_PAGE_GROUP.php
Normal file
15
dbd/qq/SYS_PAGE_GROUP.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace SYSTEM\DBD;
|
||||
|
||||
class SYS_PAGE_GROUP extends \SYSTEM\DB\QP {
|
||||
protected static function query(){
|
||||
return new \SYSTEM\DB\QQuery(get_class(),
|
||||
//pg
|
||||
'SELECT * FROM '.\SYSTEM\DBD\system_page::NAME_PG
|
||||
.' WHERE "'.\SYSTEM\DBD\system_page::FIELD_GROUP.'" = $1'
|
||||
.' ORDER BY "'.\SYSTEM\DBD\system_page::FIELD_ID.'"',
|
||||
//mys
|
||||
'SELECT * FROM '.\SYSTEM\DBD\system_page::NAME_MYS
|
||||
.' WHERE `'.\SYSTEM\DBD\system_page::FIELD_GROUP.'` = ?'
|
||||
.' ORDER BY '.\SYSTEM\DBD\system_page::FIELD_ID
|
||||
);}}
|
||||
@ -18,11 +18,7 @@ INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `nam
|
||||
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (40, 0, 2, 10, 'text', 'request', 'STRING');
|
||||
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (41, 0, 2, 10, 'text', 'lang', 'LANG');
|
||||
|
||||
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (50, 0, 2, 10, 'pagestates', 'group', 'UINT');
|
||||
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (51, 0, 1, 50, NULL, 'js', NULL);
|
||||
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (52, 0, 2, 50, NULL, 'group', 'UINT');
|
||||
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (55, 0, 1, 50, NULL, 'css', NULL);
|
||||
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (56, 0, 2, 55, NULL, 'group', 'UINT');
|
||||
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (50, 0, 2, 10, 'pages', 'group', 'UINT');
|
||||
|
||||
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (90, 42, 4, -1, NULL, '_lang', 'LANG');
|
||||
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (91, 42, 4, -1, NULL, '_result', 'RESULT');
|
||||
@ -1,4 +1,4 @@
|
||||
CREATE TABLE `system_pagestates` (
|
||||
CREATE TABLE `system_page` (
|
||||
`group` INT(10) UNSIGNED NOT NULL,
|
||||
`id` CHAR(50) NOT NULL,
|
||||
`div` CHAR(50) NOT NULL,
|
||||
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
namespace SYSTEM\DBD;
|
||||
|
||||
class system_pagestates {
|
||||
const NAME_PG = 'system.pagestates';
|
||||
const NAME_MYS = 'system_pagestates';
|
||||
class system_page {
|
||||
const NAME_PG = 'system.page';
|
||||
const NAME_MYS = 'system_page';
|
||||
|
||||
const FIELD_GROUP = 'group';
|
||||
const FIELD_ID = 'id';
|
||||
@ -1,3 +1,3 @@
|
||||
<?php
|
||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__),'SYSTEM\FILES');
|
||||
require_once dirname(__FILE__).'/register_sys_files.php';
|
||||
\SYSTEM\FILES\files::registerFolder(dirname(__FILE__).'/sys/','sys');
|
||||
@ -1,2 +0,0 @@
|
||||
<?php
|
||||
\SYSTEM\FILES\files::registerFolder(dirname(__FILE__).'/sys_js/','sys_js');
|
||||
109
files/sys/system.js
Normal file
109
files/sys/system.js
Normal file
@ -0,0 +1,109 @@
|
||||
var system = null;
|
||||
|
||||
//mother object
|
||||
function SYSTEM(endpoint, group,start_state){
|
||||
system = this;
|
||||
this.endpoint = endpoint;
|
||||
this.group = group;
|
||||
this.pages = null;
|
||||
this.start_state = start_state;
|
||||
this.go_state(start_state);
|
||||
}
|
||||
//internal function to handle pagestate results
|
||||
SYSTEM.prototype.handle_call_pages = function (data) {
|
||||
if(data['status']){
|
||||
newps = data['result'];
|
||||
console.log('SYSTEM: load pages: '+system.endpoint+':'+system.group+' - success');
|
||||
result = true;
|
||||
} else {
|
||||
console.log('SYSTEM-ERROR: Problem with your Pages: '+data['result']['message']);
|
||||
result = false;}
|
||||
};
|
||||
//send a call to the endpoint
|
||||
SYSTEM.prototype.call = function(call,success,data,data_type,async){
|
||||
$.ajax({
|
||||
async: async,
|
||||
data: data,
|
||||
dataType: data_type,
|
||||
url: this.endpoint+'?'+call,
|
||||
success: success,
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown){console.log(call);}
|
||||
});
|
||||
};
|
||||
//get the pages and save em
|
||||
SYSTEM.prototype.load_page = function(){
|
||||
result = false;
|
||||
newps = this.pages;
|
||||
if(!this.pages){
|
||||
this.call('call=pages&group='+this.group,this.handle_call_pages,{},"json",false);
|
||||
} else { result = true;}
|
||||
this.pages = newps;
|
||||
return result;
|
||||
};
|
||||
//load a pagestatewith given id
|
||||
SYSTEM.prototype.load = function(id){
|
||||
if(!system.load_page()){
|
||||
console.log('SYSTEM-ERROR: Problem with your Pages');
|
||||
return false;}
|
||||
var push = true;
|
||||
var found = false;
|
||||
system.pages.forEach(function(entry) {
|
||||
if(entry['id'] === id){
|
||||
found = true;
|
||||
//write new state
|
||||
if(push){
|
||||
window.history.pushState(null, "", '#'+id);
|
||||
push = false;}
|
||||
//load pages
|
||||
$.ajax({
|
||||
async: false,
|
||||
data: {},
|
||||
dataType: 'html',
|
||||
url: entry['url'],
|
||||
success: function(data){
|
||||
$(entry['div']).html(data);
|
||||
console.log('SYSTEM: load page: '+id+entry['div']+' - success');},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown){console.log(errorThrown);}
|
||||
});
|
||||
//load css
|
||||
for(var i=0; i < entry['css'].length; i++){
|
||||
system.load_css(entry['css'][i]);}
|
||||
//load js
|
||||
for(var i=0; i < entry['js'].length; i++){
|
||||
console.log('SYSTEM: load js: '+entry['js'][i]);
|
||||
$.getScript(entry['js'][i]).done(function(response, status) {
|
||||
console.log('SYSTEM: load js: '+status);
|
||||
var fn = window[entry['func']];
|
||||
if(typeof fn === 'function'){
|
||||
fn();
|
||||
console.log('SYSTEM: call func: '+entry['func']);}});
|
||||
}
|
||||
}
|
||||
});
|
||||
if(!found){
|
||||
window.history.pushState(null, "", '#');
|
||||
window.location.reload();}
|
||||
return push ? false : true;
|
||||
};
|
||||
|
||||
SYSTEM.prototype.load_css = function loadCSS(csssrc) {
|
||||
var snode = document.createElement('link');
|
||||
snode.setAttribute('type','text/css');
|
||||
snode.setAttribute('rel', 'stylesheet');
|
||||
snode.setAttribute('href',csssrc);
|
||||
document.getElementsByTagName('head')[0].appendChild(snode);
|
||||
console.log('SYSTEM: load css '+csssrc);
|
||||
};
|
||||
|
||||
//what?
|
||||
SYSTEM.prototype.cur_state = function() {
|
||||
var pathName = window.location.href;
|
||||
if (pathName.indexOf('#') != -1) {
|
||||
return pathName.split('#').pop();}
|
||||
return '';
|
||||
};
|
||||
|
||||
SYSTEM.prototype.go_state = function(default_state){
|
||||
var pageName = this.cur_state();
|
||||
this.load(pageName ? pageName : default_state);
|
||||
};
|
||||
@ -1,74 +0,0 @@
|
||||
//mother object
|
||||
function SYSTEM(endpoint, group){
|
||||
this.endpoint = endpoint;
|
||||
this.group = group;
|
||||
this.pagestates = null;
|
||||
}
|
||||
//internal function to handle pagestate result
|
||||
SYSTEM.prototype.handle_call_pagestates = function (data) {
|
||||
if(data['status']){
|
||||
newps = data['result'];
|
||||
console.log('SYSTEM: loaded Pagestates');
|
||||
result = true;
|
||||
} else {
|
||||
console.log('SYSTEM: Problem with your Pagestates.');
|
||||
result = false;}
|
||||
}
|
||||
//send a call to the endpoint
|
||||
SYSTEM.prototype.call = function(call,success,data,data_type,async){
|
||||
$.ajax({
|
||||
async: async,
|
||||
data: data,
|
||||
dataType: data_type,
|
||||
url: this.endpoint+'?'+call,
|
||||
success: success,
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown){console.log(call);}
|
||||
});
|
||||
}
|
||||
//get the pagestates and save em
|
||||
SYSTEM.prototype.load_pagestates = function(){
|
||||
result = false;
|
||||
newps = this.pagestates;
|
||||
if(!this.pagestates){
|
||||
this.call('call=pagestates&group='+this.group,this.handle_call_pagestates,{},"json",false);
|
||||
} else { result = true;}
|
||||
this.pagestates = newps;
|
||||
return result;
|
||||
};
|
||||
//load a pagestatewith given id
|
||||
SYSTEM.prototype.load = function(id){
|
||||
console.log('Load Pagestate: '+id);
|
||||
if(!this.load_pagestates()){
|
||||
return false;}
|
||||
var push = true;
|
||||
this.pagestates.forEach(function(entry) {
|
||||
if(entry['id'] === id){
|
||||
if(push){
|
||||
window.history.pushState(null, "", '#'+id);
|
||||
push = false;}
|
||||
$.ajax({
|
||||
async: false,
|
||||
data: {},
|
||||
dataType: 'html',
|
||||
url: entry['url'],
|
||||
success: function(data){$(entry['div']).html(data); var fn = window[entry['func']]; if(typeof fn === 'function'){fn()};},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown){console.log(errorThrown);}
|
||||
});
|
||||
//$(entry['div']).load(entry['url'],fn);
|
||||
|
||||
}
|
||||
});
|
||||
return push ? false : true;
|
||||
};
|
||||
//what?
|
||||
SYSTEM.prototype.cur_state = function() {
|
||||
var pathName = window.location.href;
|
||||
if (pathName.indexOf('#') != -1) {
|
||||
return pathName.split('#').pop();}
|
||||
return '';
|
||||
}
|
||||
|
||||
SYSTEM.prototype.go_state = function(default_state){
|
||||
pageName = this.cur_state();
|
||||
this.load(pageName ? pageName : default_state);
|
||||
}
|
||||
@ -3,11 +3,15 @@ namespace SYSTEM\PAGE;
|
||||
|
||||
class State {
|
||||
public static function get($group){
|
||||
return \SYSTEM\LOG\JsonResult::toString(\SYSTEM\DBD\SYS_PAGESTATES_GROUP::QA(array($group)));}
|
||||
public static function get_js($group){
|
||||
$result = array();
|
||||
|
||||
}
|
||||
public static function get_css($group){
|
||||
|
||||
}
|
||||
$res = \SYSTEM\DBD\SYS_PAGE_GROUP::QQ(array($group));
|
||||
while($row = $res->next()){
|
||||
$row['css'] = $row['js'] = array();
|
||||
if(\method_exists($row['php_class'], 'css') && \is_callable($row['php_class'].'::css')){
|
||||
$row['css'] = array_merge($row['css'], call_user_func($row['php_class'].'::css'));}
|
||||
if(\method_exists($row['php_class'], 'js') && \is_callable($row['php_class'].'::js')){
|
||||
$row['js'] = array_merge($row['js'], call_user_func($row['php_class'].'::js'));}
|
||||
$result[] = $row;}
|
||||
return \SYSTEM\LOG\JsonResult::toString($result);}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user