Multi enhancements, including auto serialization, product editing

This commit is contained in:
Deon George
2012-03-30 15:13:01 +11:00
parent d9c3394b0f
commit 6807b6ab52
30 changed files with 445 additions and 115 deletions

View File

@@ -12,17 +12,41 @@
*/
class Controller_Admin_Product extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'ajaxtranslateform'=>TRUE,
'list'=>TRUE,
'update'=>TRUE,
'view'=>TRUE,
);
public function action_ajaxtranslateform() {
$this->auto_render = FALSE;
$po = ORM::factory('product',$this->request->param('id'));
if (! $this->request->is_ajax() OR ! $po->loaded() OR ! isset($_REQUEST['key']))
$this->response->body(_('Unable to find translate data'));
else {
$pto = $po->product_translate->where('language_id','=',$_REQUEST['key'])->find();
$this->response->body(View::factory($this->viewpath())->set('pto',$pto));
}
}
/**
* Show a list of products
*/
public function action_list() {
if ($this->request->param('id'))
$prods = ORM::factory('product')->list_category($this->request->param('id'),FALSE);
else
$prods = ORM::factory('product')->order_by('active DESC,prod_plugin_file')->find_all();
Block::add(array(
'title'=>_('Customer Products'),
'body'=>Table::display(
ORM::factory('product')->order_by('active DESC,prod_plugin_file')->find_all(),
$prods,
25,
array(
'id'=>array('label'=>'ID','url'=>'product/view/'),
@@ -43,5 +67,78 @@ class Controller_Admin_Product extends Controller_TemplateDefault_Admin {
)),
));
}
/**
* Edit a product configuration
*/
public function action_update() {
$po = ORM::factory('product',$this->request->param('id'));
if (! $po->loaded())
Request::current()->redirect('welcome/index');
if ($_POST) {
if (isset($_POST['product_translate']['id']) AND ($pto=ORM::factory('product_translate',$_POST['product_translate']['id'])) AND $pto->loaded())
if (! $pto->values($_POST['product_translate'])->update()->saved())
throw new Kohana_Exception('Failed to save updates to product_translate data for record :record',array(':record'=>$po->id()));
if (! $po->values($_POST)->update()->saved())
throw new Kohana_Exception('Failed to save updates to product data for record :record',array(':record'=>$so->id()));
}
Block::add(array(
'title'=>sprintf('%s %s:%s',_('Update Product'),$po->id,$po->name()),
'body'=>View::factory($this->viewpath())
->set('po',$po)
->set('mediapath',Route::get('default/media'))
->set('plugin_form',$po->admin_update()),
));
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
$("select[name=language_id]").change(function() {
// Send the request and update sub category dropdown
$.ajax({
type: "GET",
data: "key="+$(this).val(),
dataType: "html",
cache: false,
url: "'.URL::site('admin/product/ajaxtranslateform/'.$po->id).'",
timeout: 2000,
error: function(x) {
alert("Failed to submit");
},
success: function(data) {
$("div[id=translate]").replaceWith(data);
}
});
});
});
'));
}
public function action_view() {
$po = ORM::factory('product',$this->request->param('id'));
Block::add(array(
'title'=>sprintf('%s: %s',_('Current Services Using this Product'),$po->name()),
'body'=>Table::display(
ORM::factory('service')->where('product_id','=',$po->id)->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'account->accnum()'=>array(),
'account->name()'=>array('label'=>'Account'),
'name()'=>array('label'=>'Details'),
'active'=>array('label'=>'Active'),
'price(TRUE,TRUE)'=>array('label'=>'Price','align'=>'right'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/service/view',
)),
));
}
}
?>

View File

@@ -42,6 +42,8 @@ class Controller_Product extends Controller_TemplateDefault {
Request::current()->redirect('welcome/index');
Breadcrumb::name($this->request->uri(),$cat->name);
Breadcrumb::url('product','product/categorys');
Breadcrumb::url('product/category','product/categorys');
Block::add(array(
'title'=>sprintf('%s: %s',_('Category'),$cat->name),
@@ -68,6 +70,7 @@ class Controller_Product extends Controller_TemplateDefault {
Request::current()->redirect('product_category/index');
Breadcrumb::name($this->request->uri(),$po->product_translate->find()->name);
Breadcrumb::url('product','product/categorys');
// Work out our category id for the control line
if (! empty($_GET['cid'])) {
@@ -78,6 +81,7 @@ class Controller_Product extends Controller_TemplateDefault {
Request::current()->redirect('product_category/index');
Breadcrumb::name('product/view',$co->name);
Breadcrumb::url('product/view','product/category/'.$co->id);
}
Block::add(array(