Reverted the last two commits; back to eager product init.
Made product creation a separate page and added a menu item for it
This commit is contained in:
parent
2e7ac9fe71
commit
9d346296bc
@ -64,20 +64,7 @@
|
|||||||
|
|
||||||
¤¤ product_page ¤¤
|
¤¤ product_page ¤¤
|
||||||
<div id="product-table">
|
<div id="product-table">
|
||||||
<form id="product-create"
|
|
||||||
action="./"
|
|
||||||
method="get">
|
|
||||||
<input type="hidden"
|
|
||||||
name="page"
|
|
||||||
value="products" />
|
|
||||||
<input type="hidden"
|
|
||||||
name="action"
|
|
||||||
value="new" />
|
|
||||||
<button>
|
|
||||||
Ny artikel
|
|
||||||
</button>
|
|
||||||
¤product_table¤
|
¤product_table¤
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
¤¤ product_table ¤¤
|
¤¤ product_table ¤¤
|
||||||
@ -125,9 +112,6 @@
|
|||||||
<datalist id="template_suggest"></datalist>
|
<datalist id="template_suggest"></datalist>
|
||||||
<input type="hidden"
|
<input type="hidden"
|
||||||
name="page"
|
name="page"
|
||||||
value="products" />
|
|
||||||
<input type="hidden"
|
|
||||||
name="action"
|
|
||||||
value="new" />
|
value="new" />
|
||||||
<input onFocus="JavaScript:suggest(this, 'template')"
|
<input onFocus="JavaScript:suggest(this, 'template')"
|
||||||
list="template_suggest"
|
list="template_suggest"
|
||||||
|
56
include/NewPage.php
Normal file
56
include/NewPage.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
class NewPage extends Page {
|
||||||
|
private $template = null;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
if(isset($_GET['template'])) {
|
||||||
|
$template = $_GET['template'];
|
||||||
|
if($template) {
|
||||||
|
try {
|
||||||
|
$this->template = new Template($template, 'name');
|
||||||
|
} catch(Exception $e) {
|
||||||
|
$this->template = null;
|
||||||
|
$this->error = 'Det finns ingen mall med det namnet.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function render_body() {
|
||||||
|
print($this->build_new_page());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_new_page() {
|
||||||
|
$template = '';
|
||||||
|
$fields = '';
|
||||||
|
$tags = '';
|
||||||
|
if($this->template) {
|
||||||
|
$template = $this->template->get_name();
|
||||||
|
foreach($this->template->get_fields() as $field) {
|
||||||
|
$fields .= replace(array('name' => ucfirst($field),
|
||||||
|
'key' => $field,
|
||||||
|
'value' => ''),
|
||||||
|
$this->fragments['info_item']);
|
||||||
|
}
|
||||||
|
foreach($this->template->get_tags() as $tag) {
|
||||||
|
$tags .= replace(array('tag' => ucfirst($tag)),
|
||||||
|
$this->fragments['tag']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$out = replace(array('template' => $template),
|
||||||
|
$this->fragments['template_management']);
|
||||||
|
$out .= replace(array('id' => '',
|
||||||
|
'name' => '',
|
||||||
|
'brand' => '',
|
||||||
|
'serial' => '',
|
||||||
|
'invoice' => '',
|
||||||
|
'tags' => $tags,
|
||||||
|
'info' => $fields,
|
||||||
|
'label' => '',
|
||||||
|
'hidden' => 'hidden'),
|
||||||
|
$this->fragments['product_details']);
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -9,6 +9,7 @@ abstract class Page extends Responder {
|
|||||||
protected $menuitems = array('checkout' => 'Låna',
|
protected $menuitems = array('checkout' => 'Låna',
|
||||||
'return' => 'Lämna',
|
'return' => 'Lämna',
|
||||||
'products' => 'Artiklar',
|
'products' => 'Artiklar',
|
||||||
|
'new' => 'Ny artikel',
|
||||||
'users' => 'Låntagare',
|
'users' => 'Låntagare',
|
||||||
'inventory' => 'Inventera',
|
'inventory' => 'Inventera',
|
||||||
'history' => 'Historik',
|
'history' => 'Historik',
|
||||||
@ -167,7 +168,7 @@ abstract class Page extends Responder {
|
|||||||
$rows .= replace(array('status' => $status,
|
$rows .= replace(array('status' => $status,
|
||||||
'item_link' => $prodlink,
|
'item_link' => $prodlink,
|
||||||
'serial' => $product->get_serial(),
|
'serial' => $product->get_serial(),
|
||||||
'note' => $note,),
|
'note' => $note),
|
||||||
$this->fragments['product_row']);
|
$this->fragments['product_row']);
|
||||||
}
|
}
|
||||||
return replace(array('rows' => $rows),
|
return replace(array('rows' => $rows),
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
class Product {
|
class Product {
|
||||||
private $id;
|
private $id = 0;
|
||||||
private $brand;
|
private $brand = '';
|
||||||
private $name;
|
private $name = '';
|
||||||
private $invoice;
|
private $invoice = '';
|
||||||
private $serial;
|
private $serial = '';
|
||||||
private $createtime;
|
private $createtime = null;
|
||||||
private $discardtime;
|
private $discardtime = null;
|
||||||
private $info;
|
private $info = array();
|
||||||
private $tags;
|
private $tags = array();
|
||||||
|
|
||||||
public static function create_product(
|
public static function create_product(
|
||||||
$brand,
|
$brand,
|
||||||
$name,
|
$name,
|
||||||
$invoice,
|
$invoice,
|
||||||
$serial,
|
$serial,
|
||||||
$info,
|
$info = array(),
|
||||||
$tags
|
$tags = array()
|
||||||
) {
|
) {
|
||||||
$now = time();
|
$now = time();
|
||||||
begin_trans();
|
begin_trans();
|
||||||
@ -28,15 +28,11 @@ class Product {
|
|||||||
bind($ins_prod, 'ssssi', $brand, $name, $invoice, $serial, $now);
|
bind($ins_prod, 'ssssi', $brand, $name, $invoice, $serial, $now);
|
||||||
execute($ins_prod);
|
execute($ins_prod);
|
||||||
$product = new Product($serial, 'serial');
|
$product = new Product($serial, 'serial');
|
||||||
if(is_array($info)) {
|
foreach($info as $field => $value) {
|
||||||
foreach($info as $field => $value) {
|
$product->set_info($field, $value);
|
||||||
$product->set_info($field, $value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(is_array($tags)) {
|
foreach($tags as $tag) {
|
||||||
foreach($tags as $tag) {
|
$product->add_tag($tag);
|
||||||
$product->add_tag($tag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
commit_trans();
|
commit_trans();
|
||||||
return $product;
|
return $product;
|
||||||
@ -50,12 +46,12 @@ class Product {
|
|||||||
$search = null;
|
$search = null;
|
||||||
switch($type) {
|
switch($type) {
|
||||||
case 'id':
|
case 'id':
|
||||||
$search = prepare('select * from `product`
|
$search = prepare('select `id` from `product`
|
||||||
where `id`=?');
|
where `id`=?');
|
||||||
bind($search, 'i', $clue);
|
bind($search, 'i', $clue);
|
||||||
break;
|
break;
|
||||||
case 'serial':
|
case 'serial':
|
||||||
$search = prepare('select * from `product`
|
$search = prepare('select `id` from `product`
|
||||||
where `serial`=?');
|
where `serial`=?');
|
||||||
bind($search, 's', $clue);
|
bind($search, 's', $clue);
|
||||||
break;
|
break;
|
||||||
@ -68,13 +64,9 @@ class Product {
|
|||||||
throw new Exception('Product does not exist.');
|
throw new Exception('Product does not exist.');
|
||||||
}
|
}
|
||||||
$this->id = $result['id'];
|
$this->id = $result['id'];
|
||||||
$this->brand = $result['brand'];
|
$this->update_fields();
|
||||||
$this->name = $result['name'];
|
$this->update_info();
|
||||||
$this->invoice = $result['invoice'];
|
$this->update_tags();
|
||||||
$this->serial = $result['serial'];
|
|
||||||
#$this->update_fields();
|
|
||||||
#$this->update_info();
|
|
||||||
#$this->update_tags();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function update_fields() {
|
private function update_fields() {
|
||||||
@ -250,9 +242,6 @@ class Product {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function get_info() {
|
public function get_info() {
|
||||||
if($this->info === null) {
|
|
||||||
$this->update_info();
|
|
||||||
}
|
|
||||||
return $this->info;
|
return $this->info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,9 +284,6 @@ class Product {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function get_tags() {
|
public function get_tags() {
|
||||||
if($this->tags === null) {
|
|
||||||
$this->update_tags();
|
|
||||||
}
|
|
||||||
return $this->tags;
|
return $this->tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
class ProductPage extends Page {
|
class ProductPage extends Page {
|
||||||
private $action = 'list';
|
private $action = 'list';
|
||||||
private $template = null;
|
|
||||||
private $product = null;
|
private $product = null;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
@ -9,17 +8,6 @@ class ProductPage extends Page {
|
|||||||
if(isset($_GET['action'])) {
|
if(isset($_GET['action'])) {
|
||||||
$this->action = $_GET['action'];
|
$this->action = $_GET['action'];
|
||||||
}
|
}
|
||||||
if(isset($_GET['template'])) {
|
|
||||||
$template = $_GET['template'];
|
|
||||||
if($template) {
|
|
||||||
try {
|
|
||||||
$this->template = new Template($template, 'name');
|
|
||||||
} catch(Exception $e) {
|
|
||||||
$this->template = null;
|
|
||||||
$this->error = 'Det finns ingen mall med det namnet.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(isset($_GET['id'])) {
|
if(isset($_GET['id'])) {
|
||||||
$id = $_GET['id'];
|
$id = $_GET['id'];
|
||||||
if($id) {
|
if($id) {
|
||||||
@ -36,9 +24,6 @@ class ProductPage extends Page {
|
|||||||
case 'show':
|
case 'show':
|
||||||
$this->subtitle = 'Artikeldetaljer';
|
$this->subtitle = 'Artikeldetaljer';
|
||||||
break;
|
break;
|
||||||
case 'new':
|
|
||||||
$this->subtitle = 'Ny artikel';
|
|
||||||
break;
|
|
||||||
case 'list':
|
case 'list':
|
||||||
$this->subtitle = 'Artikellista';
|
$this->subtitle = 'Artikellista';
|
||||||
break;
|
break;
|
||||||
@ -55,9 +40,6 @@ class ProductPage extends Page {
|
|||||||
case 'show':
|
case 'show':
|
||||||
print($this->build_product_details());
|
print($this->build_product_details());
|
||||||
break;
|
break;
|
||||||
case 'new':
|
|
||||||
print($this->build_new_page());
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,37 +138,5 @@ class ProductPage extends Page {
|
|||||||
return replace(array('attachments' => $items),
|
return replace(array('attachments' => $items),
|
||||||
$this->fragments['attachment_list']);
|
$this->fragments['attachment_list']);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function build_new_page() {
|
|
||||||
$template = '';
|
|
||||||
$fields = '';
|
|
||||||
$tags = '';
|
|
||||||
if($this->template) {
|
|
||||||
$template = $this->template->get_name();
|
|
||||||
foreach($this->template->get_fields() as $field) {
|
|
||||||
$fields .= replace(array('name' => ucfirst($field),
|
|
||||||
'key' => $field,
|
|
||||||
'value' => ''),
|
|
||||||
$this->fragments['info_item']);
|
|
||||||
}
|
|
||||||
foreach($this->template->get_tags() as $tag) {
|
|
||||||
$tags .= replace(array('tag' => ucfirst($tag)),
|
|
||||||
$this->fragments['tag']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$out = replace(array('template' => $template),
|
|
||||||
$this->fragments['template_management']);
|
|
||||||
$out .= replace(array('id' => '',
|
|
||||||
'name' => '',
|
|
||||||
'brand' => '',
|
|
||||||
'serial' => '',
|
|
||||||
'invoice' => '',
|
|
||||||
'tags' => $tags,
|
|
||||||
'info' => $fields,
|
|
||||||
'label' => '',
|
|
||||||
'hidden' => 'hidden'),
|
|
||||||
$this->fragments['product_details']);
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -85,6 +85,8 @@ function make_page($page) {
|
|||||||
return new SearchPage();
|
return new SearchPage();
|
||||||
case 'products':
|
case 'products':
|
||||||
return new ProductPage();
|
return new ProductPage();
|
||||||
|
case 'new':
|
||||||
|
return new NewPage();
|
||||||
case 'users':
|
case 'users':
|
||||||
return new UserPage();
|
return new UserPage();
|
||||||
case 'inventory':
|
case 'inventory':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user