saimod api statesystem implemented

This commit is contained in:
Ulf Gebhardt 2015-04-11 19:06:05 +02:00
parent 066ad2f158
commit 41111f1f8b
11 changed files with 114 additions and 141 deletions

View File

@ -89,7 +89,10 @@ INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `nam
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (606, 42, 2, 600, 'addcall', 'name', 'STRING'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (606, 42, 2, 600, 'addcall', 'name', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (607, 42, 2, 600, 'addcall', 'verify', 'ALL'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (607, 42, 2, 600, 'addcall', 'verify', 'ALL');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (608, 42, 2, 600, 'deletecall', 'ID', 'INT'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (608, 42, 2, 600, 'deletecall', 'ID', 'INT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (609, 42, 2, 600, 'deletedialog', 'ID', 'INT'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (609, 42, 2, 600, 'deletecall', 'group', 'INT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (610, 42, 2, 600, 'deletedialog', 'ID', 'INT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (611, 42, 2, 600, 'deletedialog', 'group', 'INT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (620, 42, 3, 600, 'list', 'group', 'INT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (700, 42, 0, 0, '_SYSTEM_SAI_saimod_sys_text', 'action', NULL); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (700, 42, 0, 0, '_SYSTEM_SAI_saimod_sys_text', 'action', NULL);

View File

@ -1,97 +1,54 @@
var currentID = '';
function init_saimod_sys_api() { function init_saimod_sys_api() {
saimod_sys_api_tree(); $('#tabs_log a').click(function (e) {
saimod_sys_api_register_clickevents(); $('#tabs_log li').each(function(){
$(this).removeClass('active');});
} $(this).parent().addClass('active');
function saimod_sys_api_loadcontent(){
$('#api_wrapper').load('./sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_api', function(){
console.log('api module loaded');
saimod_sys_api_register_clickevents();
}); });
api_menu();
}
function saimod_sys_api_register_clickevents(){
$('tr.api_entries').click(function() {
currentID = $(this).attr("id");
$.ajax({
url: './sai.php',
data: { sai_mod: '.SYSTEM.SAI.saimod_sys_api',
action: 'deletedialog',
ID: currentID},
type: 'GET',
success: function(data) {
console.log("works");
$('#api_content').html(data);
$('#del_api_close').click(function() {
console.log("olenski");
$('#del_api_description').hide();
$('#del_api_del').show();
saimod_sys_api_loadcontent();
});
$('#del_api_del').click(function() {
$.ajax({
url: './sai.php',
data: { sai_mod: '.SYSTEM.SAI.saimod_sys_api',
action: 'deletecall',
ID: currentID},
type: 'GET',
success: function(data) {
console.log("api call deleted");
$('#api_deletedialog').html('<p>Api call deleted!</p>');
$('#del_api_del').hide();
}});});}});});
$('#addcall').click(function() { $('#addcall').click(function() {
var id = $('#new_call_id').val(); $.ajax({ url: './sai.php',
var group = $('#new_call_group').val();
var type = $('#new_call_type').val();
var parentid = $('#new_call_parentid').val();
var parentvalue = $('#new_call_parentvalue').val();
var name = $('#new_call_name').val();
var verify = $('#new_call_verify').val();
$.ajax({
url: './sai.php',
data: { sai_mod: '.SYSTEM.SAI.saimod_sys_api', data: { sai_mod: '.SYSTEM.SAI.saimod_sys_api',
action: 'addcall', action: 'addcall',
ID: id, ID: $('#new_call_id').val(),
group: group, group: $('#new_call_group').val(),
type: type, type: $('#new_call_type').val(),
parentID: parentid, parentID: $('#new_call_parentid').val(),
parentValue : parentvalue, parentValue : $('#new_call_parentvalue').val(),
name: name, name: $('#new_call_name').val(),
verify: verify}, verify: $('#new_call_verify').val()},
type: 'GET', type: 'GET',
success: function(data) { success: function(data) {
console.log("new api call added"); console.log("new api call added");
saimod_sys_api_loadcontent(); saimod_sys_api_loadcontent();
} }
}); });
}); });
$('#del_api_close').click(function() {
console.log("olenski");
$('#del_api_description').hide();
$('#del_api_del').show();
saimod_sys_api_loadcontent();
});
$('#localetab a').click(function (e) {e.preventDefault(); $(this).tab('show');});
} }
function saimod_sys_api_tree(){ function api_menu(){
$('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch'); $('#tabs_log li').each(function(){
$('.tree li.parent_li > span').on('click', function (e) { $(this).removeClass('active');});
var children = $(this).parent('li.parent_li').find(' > ul > li'); if($('#menu_group_'+system.cur_state().split('.')[1]).length){
if (children.is(":visible")) { $('#menu_group_'+system.cur_state().split('.')[1]).parent().addClass('active');
children.hide('fast');
$(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
} else { } else {
children.show('fast'); $('#menu_all').parent().addClass('active');}
$(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
} }
e.stopPropagation(); function init_saimod_sys_api_list(){
api_menu();}
function init_saimod_sys_api_delete(){
$('#del_api_del').click(function() {
$.ajax({ url: './sai.php',
data: { sai_mod: '.SYSTEM.SAI.saimod_sys_api',
action: 'deletecall',
ID: $(this).attr('api_id'),
group: $(this).attr('api_group')},
type: 'GET',
success: function(data) {
console.log("api call deleted");
$('#api_deletedialog').html('<p>Api call deleted!</p>');
$('#del_api_del').hide();
}
});
}); });
} }

View File

@ -5,7 +5,7 @@ class SYS_SAIMOD_API_DEL extends \SYSTEM\DB\QP {
protected static function query(){ protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(), return new \SYSTEM\DB\QQuery(get_class(),
//pg //pg
'DELETE FROM '.\SYSTEM\DBD\system_api::NAME_PG.' WHERE `ID` = $1;', 'DELETE FROM '.\SYSTEM\DBD\system_api::NAME_PG.' WHERE `ID` = $1 AND group = $2;',
//mys //mys
'DELETE FROM '.\SYSTEM\DBD\system_api::NAME_MYS.' WHERE `ID` = ?;' 'DELETE FROM '.\SYSTEM\DBD\system_api::NAME_MYS.' WHERE `ID` = ? AND `group` = ?;'
);}} );}}

View File

@ -0,0 +1,11 @@
<?php
namespace SYSTEM\DBD;
class SYS_SAIMOD_API_GET extends \SYSTEM\DB\QQ {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'SELECT * FROM system_api ORDER BY `group`, `ID` ASC;',
//mys
'SELECT * FROM system_api ORDER BY `group`, `ID` ASC;'
);}}

View File

@ -5,7 +5,7 @@ class SYS_SAIMOD_API_SINGLE_SELECT extends \SYSTEM\DB\QP {
protected static function query(){ protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(), return new \SYSTEM\DB\QQuery(get_class(),
//pg //pg
'SELECT * FROM '.\SYSTEM\DBD\system_api::NAME_PG.' WHERE ID = $1;', 'SELECT * FROM '.\SYSTEM\DBD\system_api::NAME_PG.' WHERE ID = $1 AND group = $2;',
//mys //mys
'SELECT * FROM '.\SYSTEM\DBD\system_api::NAME_MYS.' WHERE ID = ?;' 'SELECT * FROM '.\SYSTEM\DBD\system_api::NAME_MYS.' WHERE ID = ? AND `group` = ?;'
);}} );}}

View File

@ -1,9 +1,7 @@
<?php <?php
namespace SYSTEM\SAI; namespace SYSTEM\SAI;
class saimod_sys_api extends \SYSTEM\SAI\SaiModule { class saimod_sys_api extends \SYSTEM\SAI\SaiModule {
public static function sai_mod__SYSTEM_SAI_saimod_sys_api(){ public static function sai_mod__SYSTEM_SAI_saimod_sys_api(){
//$last_group = -1;
$vars = array(); $vars = array();
$con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo()); $con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo());
@ -16,13 +14,13 @@ class saimod_sys_api extends \SYSTEM\SAI\SaiModule {
$vars['tabopts'] = ''; $vars['tabopts'] = '';
$first = true; $first = true;
while($r = $res->next()){ while($r = $res->next()){
$vars2 = array( 'active' => ($first ? 'active' : ''), $vars2 = array( 'active' => ($first ? '' : ''),
'tab_id' => $r['group']); 'tab_id' => $r['group']);
$first = false; $first = false;
$vars['tabopts'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_api/tpl/tabopt.tpl'), $vars2); $vars['tabopts'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_api/tpl/tabopt.tpl'), $vars2);
} }
if(\SYSTEM\system::isSystemDbInfoPG()){ /*if(\SYSTEM\system::isSystemDbInfoPG()){
$res = $con->query('SELECT * FROM system.api ORDER BY "group", "ID" ASC;'); $res = $con->query('SELECT * FROM system.api ORDER BY "group", "ID" ASC;');
} else { } else {
$res = $con->query('SELECT * FROM system_api ORDER BY `group`, `ID` ASC;'); $res = $con->query('SELECT * FROM system_api ORDER BY `group`, `ID` ASC;');
@ -41,17 +39,27 @@ class saimod_sys_api extends \SYSTEM\SAI\SaiModule {
foreach($tabs as $tab){ foreach($tabs as $tab){
$tab['active'] = ($first ? 'active' : ''); $tab['active'] = ($first ? 'active' : '');
$first = false; $first = false;
$vars['tabs'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_api/tpl/tab.tpl'), $tab);} $vars['tabs'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_api/tpl/tab.tpl'), $tab);}*/
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_api/tpl/tabs.tpl'), $vars); return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_api/tpl/tabs.tpl'), $vars);
/* $result = "";
$result .= '<tr class="'.self::tablerow_class($r['type']).'">'.'<td>'.$r['ID'].'</td>'.'<td>'.$r['group'].'</td>'.'<td>'.$r['type'].'</td>'.'<td>'.$r['parentID'].'</td>'.'<td>'.$r['parentValue'].'</td>'.'<td>'.$r['name'].'</td>'.'<td>'.$r['verify'].'</td>'.'</tr>';
return $result;*/
} }
public static function sai_mod__system_sai_saimod_sys_api_action_deletedialog($ID){ public static function sai_mod__system_sai_saimod_sys_api_action_list($group=null){
$res = \SYSTEM\DBD\SYS_SAIMOD_API_SINGLE_SELECT::Q1(array($ID)); $res = \SYSTEM\DBD\SYS_SAIMOD_API_GET::QQ();
$tab = array('content' => '');
while($r = $res->next()){
if($group != null && $r['group'] != $group){
continue;}
$tab['tab_id'] = $r['group'];
$r['tr_class'] = self::tablerow_class($r['type']);
$r['type'] = self::type_names($r['type']);
$tab['content'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_api/tpl/list_entry.tpl'), $r);
}
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_api/tpl/tab.tpl'), $tab);
}
public static function sai_mod__system_sai_saimod_sys_api_action_deletedialog($ID,$group){
$res = \SYSTEM\DBD\SYS_SAIMOD_API_SINGLE_SELECT::Q1(array($ID,$group));
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_api/tpl/delete_dialog.tpl'), $res); return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_api/tpl/delete_dialog.tpl'), $res);
} }
@ -64,10 +72,10 @@ class saimod_sys_api extends \SYSTEM\SAI\SaiModule {
return \SYSTEM\LOG\JsonResult::ok(); return \SYSTEM\LOG\JsonResult::ok();
} }
public static function sai_mod__system_sai_saimod_sys_api_action_deletecall($ID){ public static function sai_mod__system_sai_saimod_sys_api_action_deletecall($ID,$group){
if(!\SYSTEM\SECURITY\Security::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI_API)){ if(!\SYSTEM\SECURITY\Security::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI_API)){
throw new \SYSTEM\LOG\ERROR("You dont have edit Rights - Cant proceeed");} throw new \SYSTEM\LOG\ERROR("You dont have edit Rights - Cant proceeed");}
\SYSTEM\DBD\SYS_SAIMOD_API_DEL::QI(array($ID)); \SYSTEM\DBD\SYS_SAIMOD_API_DEL::QI(array($ID,$group));
return \SYSTEM\LOG\JsonResult::ok(); return \SYSTEM\LOG\JsonResult::ok();
} }

View File

@ -22,5 +22,5 @@
</tr> </tr>
</table> </table>
</div> </div>
<button type="button" class="btn btn-small btn-danger" id="del_api_del">Delete</button> <button type="button" class="btn btn-small btn-danger" id="del_api_del" api_id="${ID}" api_group="${group}">Delete</button>
<button type="button" class="btn btn-small" id="del_api_close">Close</button> <button type="button" class="btn btn-small" onClick="system.load('api;group.${group}');">Close</button>

View File

@ -1,4 +1,4 @@
<tr class="${tr_class} api_entries" id="${ID}" group="${group}" typ="${type}" parentID="${parentID}" parentValue="${parentValue}" name="${name}" verify="${verify}"> <tr class="${tr_class} api_entries" onClick="system.load('api(delete);group.${group};id.${ID}');" id="${ID}" group="${group}" typ="${type}" parentID="${parentID}" parentValue="${parentValue}" name="${name}" verify="${verify}">
<td>${ID}</td> <td>${ID}</td>
<td>${group}</td> <td>${group}</td>
<td>${type}</td> <td>${type}</td>

View File

@ -1,4 +1,3 @@
<div class="tab-pane ${active}" id="tab_${tab_id}">
<table class="table table-hover table-condensed" style="overflow: auto;"> <table class="table table-hover table-condensed" style="overflow: auto;">
<tr> <tr>
<th>ID</th> <th>ID</th>
@ -11,4 +10,3 @@
</tr> </tr>
${content} ${content}
</table> </table>
</div>

View File

@ -1 +1 @@
<li class="${active}"><a href="#tab_${tab_id}">Group ${tab_id}</a></li> <li class="${active}"><a href="#!api;group.${tab_id}" id="menu_group_${tab_id}">Group ${tab_id}</a></li>

View File

@ -1,13 +1,12 @@
<div id="api_wrapper">
<h4>System API</h4> <h4>System API</h4>
<hr> <hr>
<div id="api_content">
<div class="tabbable"> <div class="tabbable">
<ul class="nav nav-tabs" id="localetab"> <ul class="nav nav-tabs" id="tabs_api">
<li><a href="#!api" id="menu_all">All</a></li>
${tabopts} ${tabopts}
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
${tabs} <div class="tab-pane active" id="tab_api"></div>
</div> </div>
</div> </div>
<table class="table table-hover table-condensed" style="overflow: auto;"> <table class="table table-hover table-condensed" style="overflow: auto;">
@ -29,8 +28,5 @@
<td><input type="text" id="new_call_name" placeholder="name" style="width: 140px;"></td> <td><input type="text" id="new_call_name" placeholder="name" style="width: 140px;"></td>
<td><input type="text" id="new_call_verify" placeholder="verify" style="width: 140px;"></td> <td><input type="text" id="new_call_verify" placeholder="verify" style="width: 140px;"></td>
</tr> </tr>
</table> </table>
<button type="button" class="btn-small btn-success" id="addcall">Add</button> <button type="button" class="btn-small btn-success" id="addcall">Add</button>
</div><!-- /.modal -->
</div>