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

View File

@@ -0,0 +1,48 @@
<div class="row">
<div class="span9 offset1">
<fieldset>
<legend>Update Service</legend>
<div class="row">
<div class="span3">
<?php echo StaticList_YesNo::form('status',$o->status,FALSE,array('label'=>'Active','class'=>'span1')); ?>
</div>
</div> <!-- /row -->
<div class="row">
<div class="span5">
<?php echo StaticList_RecurSchedule::form('recure_schedule',$o->recur_schedule,FALSE,array('label'=>'Billing Period','required'));?>
</div>
</div> <!-- /row -->
<div class="row">
<div class="span5 input-append date" id="date_next_invoice_label">
<?php echo Form::input('date_next_invoice_label',$o->display('date_next_invoice'),array('class'=>'span2','label'=>'Date Last Invoice','add-on'=>'<i class="icon-calendar"></i>','disabled')); ?>
</div>
<?php echo Form::hidden('date_next_invoice',$o->date_next_invoice); ?>
</div> <!-- /row -->
<div class="row">
<div class="span3">
<?php echo StaticList_YesNo::form('taxable',$o->taxable,FALSE,array('label'=>'Taxable','class'=>'span1')); ?>
</div>
</div> <!-- /row -->
<div class="row">
<div class="span3">
<?php echo StaticList_YesNo::form('suspend_billing',$o->suspend_billing,FALSE,array('label'=>'Suspend Billing','class'=>'span1')); ?>
</div>
</div> <!-- /row -->
<?php if ($plugin_form) { echo $plugin_form; } ?>
<div class="row">
<div class="offset2">
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="button" class="btn">Cancel</button>
</div>
</div>
</fieldset>
</div> <!-- /span -->
</div> <!-- /row -->

View File

@@ -1,48 +0,0 @@
<!-- @todo NEEDS TO BE TRANSLATED -->
<?php echo Form::open(); ?>
<table width="100%">
<tr>
<td style="width: 50%; vertical-align: top;">
<table width="100%">
<tr>
<td style="width: 40%;">Service Active</td>
<td style="width: 60%;" class="data"><?php echo StaticList_YesNo::form('status',$so->status); ?></td>
</tr>
<tr>
<td>Queue</td>
<td class="data"><?php echo $so->display('queue'); ?></td>
</tr>
<tr>
<td>Billing Period</td>
<td class="data"><?php echo StaticList_RecurSchedule::form('recure_schedule',$so->product,$so->recur_schedule);?></td>
</tr>
<tr>
<td>Date Last Invoice</td>
<td class="data"><?php echo $so->display('date_last_invoice'); ?></td>
</tr>
<tr>
<td>Date Next Invoice</td>
<td class="data">
<?php echo Form::input('date_next_invoice',$so->date_next_invoice,array('id'=>'date_next_invoice')); ?>
<?php echo HTML::anchor('#',
HTML::image($mediapath->uri(array('file'=>'img/calendar.png')),array('alt'=>_('Calendar'),'style'=>'cursor: pointer;')),
array('title'=>'Click to popup a dialog to select a date graphically','onclick'=>"dateSelector('date_next_invoice')")); ?>
<script type="text/javascript">defaults['date_next_invoice'] = '%s';</script>
</td>
</tr>
<tr>
<td>Taxable</td>
<td class="data"><?php echo StaticList_YesNo::form('taxable',$so->taxable); ?></td>
</tr>
<tr>
<td>Suspend Billing</td>
<td class="data"><?php echo StaticList_YesNo::form('suspend_billing',$so->suspend_billing); ?></td>
</tr>
</table>
<?php if ($plugin_form) { echo '<br/>'.$plugin_form; } ?>
<!-- END Service Information -->
</td>
</tr>
</table>
<?php echo Form::submit('submit',_('Update'),array('class'=>'form_button')); ?>
<?php echo Form::close(); ?>