first working state of npc_vendor_template saimod

This commit is contained in:
Ulf Gebhardt 2016-01-05 09:39:46 +01:00
parent 2b31bb7fc7
commit f7f8bade45
11 changed files with 162 additions and 17 deletions

View File

@ -1,2 +1,23 @@
function init_saimod_mojotrollz_npc_vendor_template(){ function init_saimod_mojotrollz_npc_vendor_template(){
$('.btn_comment').click(function(){
entry = $(this).attr('entry');
$.ajax({ type :'POST',
url : './sai.php?sai_mod=.SAI.saimod_mojotrollz_npc_vendor_template&action=comment',
data : { entry: entry,
comment: $('#input_comment_'+entry).val()},
success : function(data) {
if(data.status){
system.reload();
}else{
alert('Problem: '+data);}
}
});
});
$('#btn_search').click(function(){
search = { entry: $('#input_search_entry').val(),
items: $('#input_search_items').val(),
comments: $('#input_search_comments').val()}
system.load('mojotrollz_npc_vendor_template;search.'+JSON.stringify(search),true);
});
} }

View File

@ -1,10 +1,75 @@
<?php <?php
namespace SAI; namespace SAI;
class saimod_mojotrollz_npc_vendor_template extends \SYSTEM\SAI\SaiModule { class saimod_mojotrollz_npc_vendor_template extends \SYSTEM\SAI\SaiModule {
public static function sai_mod__SAI_saimod_mojotrollz_npc_vendor_template(){ public static function sai_mod__SAI_saimod_mojotrollz_npc_vendor_template_action_comment($entry,$comment){
\SQL\NPC_VENDOR_TEMPLATE_COMMENT::QI(array($entry,$comment));
return \JsonResult::ok();
}
public static function sai_mod__SAI_saimod_mojotrollz_npc_vendor_template_action_vendor($entry){
return 'test';
}
public static function sai_mod__SAI_saimod_mojotrollz_npc_vendor_template($search='{}',$page=0){
$vars = array(); $vars = array();
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \PSAI(),'saimod_mojotrollz_npc_vendor_template/tpl/npc_vendor_template.tpl'), $vars);} $vars['search_entry'] = $vars['search_items'] = $vars['search_comments'] = '';
$query = 'SELECT npc_vendor_template.entry, COUNT(*) as items, comments '.
'FROM npc_vendor_template '.
'LEFT JOIN '.\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DB_DBNAME).'.mojotrollz_npc_vendor_template '.
'ON npc_vendor_template.entry = mojotrollz_npc_vendor_template.entry';
$query_group = ' GROUP BY npc_vendor_template.entry';
$query_search = '';
$query_search_having = '';
$query_vars = array();
$search_ = \json_decode($search,true);
if(\is_array($search_)){
if(\array_key_exists('entry', $search_) && $search_['entry'] != ''){
$query_search .= ' AND npc_vendor_template.entry = ?';
$query_vars[] = $search_['entry'];
$vars['search_entry'] = $search_['entry'];
}
if(\array_key_exists('items', $search_) && $search_['items'] != ''){
$query_search_having .= ' AND items = ?';
$query_vars[] = $search_['items'];
$vars['search_items'] = $search_['items'];
}
if(\array_key_exists('comments', $search_) && $search_['comments'] != ''){
$query_search .= ' AND comments LIKE ?';
$query_vars[] = '%'.$search_['comments'].'%';
$vars['search_comments'] = $search_['comments'];
}
}
if($query_search){
$query = $query.' WHERE '.\substr($query_search, 4);}
$query .= $query_group;
if($query_search_having){
$query = $query.' HAVING '.\substr($query_search_having, 4);}
$query_count = 'SELECT COUNT(*) as count FROM ('.$query.') t1';
$con = new \SYSTEM\DB\Connection(new \SQL\mangos_one_world_test());
if(count($query_vars) > 0){
$count = $con->prepare('count_npc_vendor_template',$query_count,$query_vars)->next()['count'];
$res = $con->prepare('select_npc_vendor_template', $query, $query_vars);
} else {
$count = $con->query($query_count)->next()['count'];
$res = $con->query($query);}
$vars['entries'] = '';
$count_filtered = 0;
$res->seek(100*$page);
while(($row = $res->next()) && ($count_filtered < 100)){
$vars['entries'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \PSAI(),'saimod_mojotrollz_npc_vendor_template/tpl/npc_vendor_template_entry.tpl'), $row);
$count_filtered++;
}
$vars['pagination'] = '';
$vars['page'] = $page;
$vars['page_last'] = ceil($count/100)-1;
for($i=0;$i < ceil($count/100);$i++){
$data = array('page' => $i,'search' => $search, 'active' => ($i == $page) ? 'active' : '');
$vars['pagination'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \PSAI(),'saimod_mojotrollz_npc_vendor_template/tpl/npc_vendor_template_pagination.tpl'), $data);
}
$vars['search'] = $search;
$vars['count'] = $count_filtered.'/'.$count;
$vars = array_merge($vars, \SYSTEM\PAGE\text::tag('basic'));
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \PSAI(),'saimod_mojotrollz_npc_vendor_template/tpl/npc_vendor_template.tpl'), $vars);
}
public static function html_li_menu(){return '<li role="separator" class="nav-divider"></li><li><a data-toggle="tooltip" data-placement="left" title="test server: npc_vendor_template" href="#!mojotrollz_npc_vendor_template"><span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>&nbsp;&nbsp;Vendor Template</a></li>';} public static function html_li_menu(){return '<li role="separator" class="nav-divider"></li><li><a data-toggle="tooltip" data-placement="left" title="test server: npc_vendor_template" href="#!mojotrollz_npc_vendor_template"><span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>&nbsp;&nbsp;Vendor Template</a></li>';}
public static function right_public(){return false;} public static function right_public(){return false;}
public static function right_right(){return \SYSTEM\SECURITY\Security::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI);} public static function right_right(){return \SYSTEM\SECURITY\Security::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI);}

View File

@ -0,0 +1,8 @@
CREATE TABLE `mojotrollz_npc_vendor_template` (
`entry` MEDIUMINT(8) UNSIGNED NOT NULL,
`comments` TEXT NULL,
PRIMARY KEY (`entry`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;

View File

@ -1 +1,5 @@
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5300, 42, 0, 0, '_SAI_saimod_mojotrollz_npc_vendor_template', 'action', NULL); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5300, 42, 0, 0, '_SAI_saimod_mojotrollz_npc_vendor_template', 'action', NULL);
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5301, 42, 3, 0, '_SAI_saimod_mojotrollz_npc_vendor_template', 'search', 'JSON');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5302, 42, 3, 0, '_SAI_saimod_mojotrollz_npc_vendor_template', 'page', 'INT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5310, 42, 2, 5300, 'comment', 'entry', 'INT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5311, 42, 2, 5300, 'comment', 'comment', 'STRING');

View File

@ -1 +1 @@
INSERT INTO `system_page` (`id`, `group`, `name`, `state`, `parent_id`, `login`, `type`, `div`, `url`, `func`, `php_class`) VALUES (530, 42, 'mojotrollz_npc_vendor_template', 'mojotrollz_npc_vendor_template', -1, 0, 0, '#content', './sai.php?sai_mod=.SAI.saimod_mojotrollz_npc_vendor_template', 'init_saimod_mojotrollz_npc_vendor_template', '\\SAI\\saimod_mojotrollz_npc_vendor_template'); INSERT INTO `system_page` (`id`, `group`, `name`, `state`, `parent_id`, `login`, `type`, `div`, `url`, `func`, `php_class`) VALUES (530, 42, 'mojotrollz_npc_vendor_template', 'mojotrollz_npc_vendor_template', -1, 0, 0, '#content', './sai.php?sai_mod=.SAI.saimod_mojotrollz_npc_vendor_template&search=${search}&page=${page}', 'init_saimod_mojotrollz_npc_vendor_template', '\\SAI\\saimod_mojotrollz_npc_vendor_template');

View File

@ -0,0 +1,10 @@
<?php
namespace SQL;
class NPC_VENDOR_TEMPLATE_COMMENT extends \SYSTEM\DB\QP {
public static function get_class(){return \get_class();}
public static function mysql(){return
'REPLACE INTO mojotrollz_npc_vendor_template '.
'(entry,comments) '.
'VALUES(?,?);';
}
}

View File

@ -1,11 +1,29 @@
<h6>${basic_rows}: ${count} ${basic_page}: ${page}</h6>
<table class="sai_table" style="width: 100%;"> <table class="sai_table" style="width: 100%;">
<tr> <tr>
<th>entry</th> <th>entry</th>
<th>item</th> <th>items</th>
<th>maxcount</th> <th>comments</th>
<th>incrtime</th> <th>actions</th>
<th>ExtendedCost</th> </tr>
<th>condition_id</th> <tr>
<td>
<input class="input-medium search-query action-control" id="input_search_entry" type="text" placeholder="${basic_placeholder_search}" size="20" value="${search_entry}"/>
</td>
<td>
<input class="input-medium search-query action-control" id="input_search_items" type="text" placeholder="${basic_placeholder_search}" size="20" value="${search_items}"/>
</td>
<td>
<input class="input-medium search-query action-control" id="input_search_comments" type="text" placeholder="${basic_placeholder_search}" size="20" value="${search_comments}"/>
</td>
<td>
<button class="btn-sm btn btn-success" id="btn_search" type="submit"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> ${basic_search}</button>
</td>
</tr> </tr>
${entries} ${entries}
</table> </table>
<ul class="pagination">
<li><a href="#!mojotrollz_npc_vendor_template;search.${search};page.0">&laquo;</a></li>
${pagination}
<li><a href="#!mojotrollz_npc_vendor_template;search.${search};page.${page_last}">&raquo;</a></li>
</ul>

View File

@ -1,8 +1,10 @@
<tr> <tr>
<td>${entry}</td> <td><a href="#!mojotrollz_npc_vendor_template_vendor;entry.${entry}">${entry}</a></td>
<td>${item}</td> <td>${items}</td>
<td>${maxcount}</td> <td>
<td>${incrtime}</td> <input class="input-medium search-query action-control" id="input_comment_${entry}" type="text" size="20" value="${comments}"/>
<td>${ExtendedCost}</td> </td>
<td>${condition_id}</td> <td>
<button class="btn-sm btn btn-success btn_comment" entry="${entry}" type="submit"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Comment</button>
</td>
</tr> </tr>

View File

@ -0,0 +1 @@
<li class="${active}"><a href="#!mojotrollz_npc_vendor_template;search.${search};page.${page}">${page}</a></li>

View File

@ -0,0 +1,8 @@
<?php
namespace SQL;
class mangos_one_world extends \SYSTEM\DB\DBInfoMYS {
public function __construct() {
parent::__construct('mangos_one_world', 'mojotrolls_dev', 'dsjgfasudzfsvad', '127.0.0.1');}
}

View File

@ -0,0 +1,8 @@
<?php
namespace SQL;
class mangos_one_world_test extends \SYSTEM\DB\DBInfoMYS {
public function __construct() {
parent::__construct('mangos_one_world_test', 'mojotrolls_dev', 'dsjgfasudzfsvad', '127.0.0.1');}
}