Admin service updates for ssl, adsl

This commit is contained in:
Deon George
2013-11-09 15:51:08 +11:00
parent 2d9d7f383c
commit 158a4f9e47
13 changed files with 235 additions and 170 deletions

View File

@@ -115,50 +115,95 @@ class Controller_Admin_Service extends Controller_Service {
}
public function action_update() {
$id = $this->request->param('id');
list($id,$output) = Table::page(__METHOD__);
$so = ORM::factory('Service',$id);
if (! $so->loaded())
HTTP::redirect('welcome/index');
if ($_POST) {
if (isset($_POST['plugin']) AND $_POST['plugin'])
if (! $so->plugin()->values($_POST['plugin'])->update()->saved())
throw new Kohana_Exception('Failed to save updates to plugin data for record :record',array(':record'=>$so->id()));
// Entry updated
if (isset($_POST['plugin']) AND $_POST['plugin']) {
$p = $so->plugin();
if (! $so->values($_POST)->update()->saved())
throw new Kohana_Exception('Failed to save updates to service data for record :record',array(':record'=>$so->id()));
if ($p->values($_POST['plugin'])->changed() AND $p->check()) {
try {
$p->values($_POST['plugin'])->save();
SystemMessage::factory()
->title('Record PLUGIN updated')
->type('success')
->body(_('Your Charge record has been recorded/updated.'));
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('models');
SystemMessage::factory()
->title('Record PLUGIN NOT updated')
->type('error')
->body(join('<br/>',array_values($errors)));
$so->reload();
}
}
}
if ($so->values($_POST)->changed() AND $so->check()) {
try {
$so->values($_POST)->save();
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your Charge record has been recorded/updated.'));
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('models');
SystemMessage::factory()
->title('Record NOT updated')
->type('error')
->body(join('<br/>',array_values($errors)));
$so->reload();
}
}
}
Block::add(array(
'title'=>sprintf('%s %s:%s',_('Update Service'),$so->id(),$so->name()),
'body'=>View::factory($this->viewpath())
->set('so',$so)
->set('mediapath',Route::get('default/media'))
->set('plugin_form',$so->admin_update()),
));
Script::factory()
->type('file')
->data('media/theme/bootstrap/vendor/datepicker/js/bootstrap-datepicker.js');
Style::factory()
->type('file')
->data('media/theme/bootstrap/vendor/datepicker/css/datepicker.css');
Script::factory()
->type('stdin')
->data('
var nowTemp = new Date();
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
$(document).ready(function() {
$("#date_next_invoice_label").datepicker({
autoclose : true,
startDate : now,
format : "dd-M-yyyy",
todayBtn : true,
}).on("hide",function(ev) {
$("input[name=date_next_invoicel]").val(ev.date.valueOf()/1000);
});
});
');
Block::factory()
->type('form-horizontal')
->title(sprintf('%s: %s %s',_('Update Service'),$id,$so->name()))
->title_icon('icon-wrench')
->body(View::factory('service/admin/edit')
->set('o',$so)
->set('plugin_form',$so->admin_update())
);
// @todo Investigate a better way of preparing for jscalendar
Script::add(array(
'type'=>'file',
'data'=>'js/dhtml.calendar.js',
));
Script::add(array(
'type'=>'file',
'data'=>'js/dhtml.calendar-setup.js',
));
Script::add(array(
'type'=>'file',
'data'=>'js/dhtml.calendar-en.js',
));
Script::add(array(
'type'=>'file',
'data'=>'js/dhtml.date_selector.js',
));
Style::add(array(
'type'=>'file',
'data'=>'css/dhtml.calendar.css',
));
}
public function action_view() {
@@ -173,8 +218,8 @@ class Controller_Admin_Service extends Controller_Service {
$doutput = $loutput = '';
$loutput .= View::factory($this->viewpath())
->set('so',$so);
$loutput .= View::factory('service/admin/view')
->set('o',$so);
// Validate the transactions
$bt = NULL;
@@ -241,7 +286,7 @@ class Controller_Admin_Service extends Controller_Service {
));
$output .= View::factory('service/user/view')
->set('so',$so);
->set('o',$so);
Block::add(array(
'title'=>sprintf('%s: %s',$so->id(),$so->service_name()),

View File

@@ -13,11 +13,6 @@ abstract class Model_Service_Plugin extends ORM_OSB {
// Reset any sorting that may be defined in our parent
protected $_sorting = array();
/**
* Form info for admins to update
*/
abstract public function admin_update();
/**
* Our service name as defined in the DB
*/
@@ -46,6 +41,14 @@ abstract class Model_Service_Plugin extends ORM_OSB {
abstract public function username_value();
abstract public function password_value();
/**
* Form info for admins to update
*/
public function admin_update() {
return View::factory(sprintf('service/admin/plugin/%s/edit',$this->plugin()))
->set('o',$this);
}
public function manage_button() {
if (! $this->service->status OR $this->service->expiring())
return FALSE;
@@ -76,6 +79,10 @@ function() { $("form[id=id_"+t[0]+"_"+t[1]+"]").submit(); });
return TRUE;
}
protected function plugin() {
return strtolower(preg_replace('/(.*)_([a-zA-Z]+)$/',"$2",get_class($this)));
}
/**
* Get specific service details for use in other modules
* For Example: Invoice