gallery add preview

This commit is contained in:
Ulf Gebhardt 2014-05-22 03:43:07 +02:00
parent 3a2f301c04
commit 7fa44d1901
8 changed files with 114 additions and 7 deletions

View File

@ -0,0 +1,11 @@
<?php
namespace DBD;
class SAIMOD_WEBCRAFT_GALLERY_GALLERY_ITEM_ADD extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'',
//mys
'INSERT INTO webcraft_gallery (gallery, position, heading, description, file_cat, file_id) VALUES (?,?,?,?,?,?);'
);}}

View File

@ -0,0 +1,11 @@
<?php
namespace DBD;
class SAIMOD_WEBCRAFT_GALLERY_GALLERY_ITEM_DELETE extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'',
//mys
'DELETE FROM webcraft_gallery WHERE ID = ?;'
);}}

View File

@ -14,10 +14,50 @@ function register_controlls(){
$('#tab_gallery').load(SAI_ENDPOINT+'sai_mod=saimod_webcraft_gallery&action=showgalleryitem&gallery='+$(this).attr('gallery')+'&id='+$(this).attr('galleryid'), function(){
$('#btn_back').click(function(){
load_tab($(this).attr('gallery'));});
$('#btn_del').click(function(){
$.ajax({
url: SAI_ENDPOINT+'sai_mod=saimod_webcraft_gallery&action=delgalleryitem',
type: 'GET',
data: { id : $(this).attr('galleryid')},
success: function (data) {
if(!data || !data['status']){
alert("Fail: "+data);
return;}
alert("OK: "+data);
}
});
});
});
});
$('.galleryadd').click(function(){
$('#tab_gallery').load(SAI_ENDPOINT+'sai_mod=saimod_webcraft_gallery&action=addgallery', function(){
$('#input_add_file_cat').change(function(){
$('#input_add_file_id').load(SAI_ENDPOINT+'sai_mod=saimod_webcraft_gallery&action=select_options_id&cat='+$('#input_add_file_cat').val(),function(){
$('#img_preview').attr('src', './api.php?call=files&cat='+$('#input_add_file_cat').val()+'&id='+$('#input_add_file_id').val());
});
});
$('#input_add_file_id').change(function(){
$('#img_preview').attr('src', './api.php?call=files&cat='+$('#input_add_file_cat').val()+'&id='+$('#input_add_file_id').val());
});
$('#img_preview').attr('src', './api.php?call=files&cat='+$('#input_add_file_cat').val()+'&id='+$('#input_add_file_id').val());
$('#btn_add').click(function(){
$.ajax({
url: SAI_ENDPOINT+'sai_mod=saimod_webcraft_gallery&action=addgalleryitem',
type: 'GET',
data: { gallery : $('#input_add_gallery').val(),
position : $('#input_add_position').val(),
heading : $('#input_add_heading').val(),
description : $('#input_add_description').val(),
file_cat : $('#input_add_file_cat').val(),
file_id : $('#input_add_file_id').val()},
success: function (data) {
if(!data || !data['status']){
alert("Fail: "+data);
return;}
alert("OK: "+data);
}
});
});
$('#btn_back').click(function(){
load_tab($(this).attr('gallery'));});
});

View File

@ -13,11 +13,40 @@ class saimod_webcraft_gallery extends \SYSTEM\SAI\SaiModule {
array('gallery' => $id, 'items' => $gallery_items));
}
public static function sai_mod_saimod_webcraft_gallery_action_addgalleryitem($gallery, $position, $heading, $description, $file_cat, $file_id){
if(!\DBD\SAIMOD_WEBCRAFT_GALLERY_GALLERY_ITEM_ADD::QI(array($gallery, $position, $heading, $description, $file_cat, $file_id))){
throw new SYSTEM\LOG\ERROR("Problem with adding Galleryitem!");}
return \SYSTEM\LOG\JsonResult::ok();}
public static function sai_mod_saimod_webcraft_gallery_action_delgalleryitem($id){
if(!\DBD\SAIMOD_WEBCRAFT_GALLERY_GALLERY_ITEM_DELETE::QI(array($id))){
throw new SYSTEM\LOG\ERROR("Problem with deleting Galleryitem!");}
return \SYSTEM\LOG\JsonResult::ok();}
public static function sai_mod_saimod_webcraft_gallery_action_addgallery(){
$vars = array();
$vars = array('file_cat_options' => self::select_options_cat(), 'file_id_options' => self::sai_mod_saimod_webcraft_gallery_action_select_options_id(array_keys(\SYSTEM\FILES\files::get())[0]));
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(), 'saimod_webcraft_gallery/saimod_webcraft_gallery_add.tpl'),$vars);
}
private static function select_options_cat($cat = null){
$result = '';
$cats = \SYSTEM\FILES\files::get();
foreach($cats as $name=>$path){
$selected = $name == $cat ? 'selected' : '';
$result .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(), 'saimod_webcraft_gallery/saimod_webcraft_gallery_file_option.tpl'), array('name' => $name, 'selected' => $selected));
}
return $result;
}
public static function sai_mod_saimod_webcraft_gallery_action_select_options_id($cat, $id = null){
$result = '';
$files = \SYSTEM\FILES\files::get($cat);
foreach($files as $file){
$selected = $file == $id ? 'selected' : '';
$result .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(), 'saimod_webcraft_gallery/saimod_webcraft_gallery_file_option.tpl'), array('name' => $file, 'selected' => $selected));
}
return $result;
}
public static function sai_mod_saimod_webcraft_gallery_action_showgalleryitem($gallery,$id){
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(), 'saimod_webcraft_gallery/saimod_webcraft_gallery_show.tpl'),
\DBD\SAIMOD_WEBCRAFT_GALLERY_GALLERY_ITEM_ID::Q1(array($gallery,$id)));

View File

@ -14,15 +14,18 @@
</tr>
<tr>
<td>Description</td>
<td><input type="text" id="input_add_heading"/></td>
<td><input type="text" id="input_add_description"/></td>
</tr>
<tr>
<td>File</td>
<td>
<input type="select" id="input_add_file_cat"/>
<input type="select" id="input_add_file_id"/>
<select id="input_add_file_cat">${file_cat_options}</select>
<select id="input_add_file_id">${file_id_options}</select>
</td>
</tr>
</table>
<img id="img_preview" src="./api.php?call=files&cat=&id="/>
</br>
</br>
<input type="button" class="btn btn-success" id="btn_add" value="Add"/>
<input type="button" class="btn" id="btn_back" value="Back" gallery="1"/>

View File

@ -0,0 +1 @@
<option value="${name}" ${selected}>${name}</option>

View File

@ -32,6 +32,6 @@
<img src="./api.php?call=files&cat=${file_cat}&id=${file_id}" id="img_preview"/>
</br>
</br>
<input type="button" class="btn btn-success" id="btn_change" value="Change"/>
<input type="button" class="btn btn-danger" id="btn_delete" value="Delete"/>
<input type="button" class="btn btn-success" id="btn_chg" galleryid="${ID}"value="Change"/>
<input type="button" class="btn btn-danger" id="btn_del" galleryid="${ID}" value="Delete"/>
<input type="button" class="btn" id="btn_back" value="Back" gallery="${gallery}"/>

View File

@ -1,2 +1,14 @@
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (201, 42, 2, 3, 'showgalleryitem', 'gallery', 'UINT0');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (202, 42, 2, 3, 'showgalleryitem', 'id', 'UINT0');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (202, 42, 2, 3, 'showgalleryitem', 'id', 'UINT0');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (205, 42, 2, 3, 'addgalleryitem', 'gallery', 'UINT0');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (206, 42, 2, 3, 'addgalleryitem', 'position', 'UINT0');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (207, 42, 2, 3, 'addgalleryitem', 'heading', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (208, 42, 2, 3, 'addgalleryitem', 'description', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (209, 42, 2, 3, 'addgalleryitem', 'file_cat', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (210, 42, 2, 3, 'addgalleryitem', 'file_id', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (215, 42, 2, 3, 'delgalleryitem', 'id', 'UINT0');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (220, 42, 2, 3, 'select_options_id', 'cat', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (221, 42, 3, 3, 'select_options_id', 'id', 'STRING');