Added Service Add, some internal consistency updates
This commit is contained in:
@@ -11,13 +11,148 @@
|
||||
*/
|
||||
class Controller_Admin_Service extends Controller_Service {
|
||||
protected $secure_actions = array(
|
||||
'add'=>TRUE,
|
||||
'ajaxaddplugin'=>TRUE,
|
||||
'edit'=>TRUE,
|
||||
'listdomainservicesbysupplier'=>TRUE,
|
||||
'listdomainservicesbydnshost'=>TRUE,
|
||||
'listhostservicesbysupplier'=>TRUE,
|
||||
'update'=>TRUE,
|
||||
'view'=>TRUE,
|
||||
);
|
||||
|
||||
public function action_add() {
|
||||
if ($this->request->post() AND $so=$this->add_edit() AND $so->loaded())
|
||||
HTTP::redirect(URL::link('admin','service/edit/'.$so->id));
|
||||
|
||||
// @todo This AJAX URL should be a service one
|
||||
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() {
|
||||
$("select[name=product_id]").change(function() {
|
||||
// If we select a blank, then dont continue
|
||||
if (this.value == 0)
|
||||
return false;
|
||||
|
||||
// Send the request and update sub category dropdown
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
data: "key="+$(this).val(),
|
||||
dataType: "html",
|
||||
cache: false,
|
||||
url: "'.URL::link('admin','service/ajaxaddplugin/',TRUE).'",
|
||||
timeout: 2000,
|
||||
error: function(x) {
|
||||
alert("Failed to submit");
|
||||
},
|
||||
success: function(data) {
|
||||
$("div[id=plugin]").empty().append(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#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);
|
||||
});
|
||||
|
||||
$("input[name=account_id_label]").typeahead({
|
||||
minLength: 2,
|
||||
source: function (query,process) {
|
||||
search("'.URL::link('admin','payment/ajaxlist').'",query,process);
|
||||
},
|
||||
|
||||
matcher: function () { return true; },
|
||||
|
||||
updater: function (item) {
|
||||
$("input[name=account_id]").val(users[item]);
|
||||
|
||||
return item;
|
||||
},
|
||||
});
|
||||
});
|
||||
');
|
||||
|
||||
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');
|
||||
|
||||
Block::factory()
|
||||
->type('form-horizontal')
|
||||
->title('Add/View Charge')
|
||||
->title_icon('icon-wrench')
|
||||
->body(View::factory('service/admin/add'));
|
||||
}
|
||||
|
||||
public function action_ajaxaddplugin() {
|
||||
$po = ORM::factory('Product',$this->request->query('key'));
|
||||
|
||||
if (! $po->loaded()) {
|
||||
$output = __('Unable to find product :key',array(':key'=>$this->request->query('key')));
|
||||
|
||||
} else {
|
||||
$output = $po->plugin()->render_order();
|
||||
}
|
||||
|
||||
$this->template->content = $output;
|
||||
}
|
||||
|
||||
public function action_edit() {
|
||||
list($id,$output) = Table::page(__METHOD__);
|
||||
|
||||
$so = $this->request->post() ? $this->add_edit($id) : ORM::factory('Service',$id);
|
||||
|
||||
if (! $so->loaded())
|
||||
HTTP::redirect('welcome/index');
|
||||
|
||||
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->plugin_edit())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function action_listdomainservicesbysupplier() {
|
||||
$svs = ORM::factory('Service')->list_bylistgroup('DOMAIN');
|
||||
Sort::MAsort($svs,'plugin()->domain_registrar_id,name()');
|
||||
@@ -114,64 +249,6 @@ class Controller_Admin_Service extends Controller_Service {
|
||||
));
|
||||
}
|
||||
|
||||
public function action_update() {
|
||||
list($id,$output) = Table::page(__METHOD__);
|
||||
|
||||
$so = ORM::factory('Service',$id);
|
||||
|
||||
if (! $so->loaded())
|
||||
HTTP::redirect('welcome/index');
|
||||
|
||||
if ($_POST) {
|
||||
// Entry updated
|
||||
if (isset($_POST['plugin']) AND $_POST['plugin']) {
|
||||
$p = $so->plugin();
|
||||
|
||||
if ($p->values($_POST['plugin'])->changed() AND ! $this->save($p))
|
||||
$p->reload();
|
||||
}
|
||||
|
||||
if ($so->values($_POST)->changed() AND ! $this->save($so))
|
||||
$so->reload();
|
||||
}
|
||||
|
||||
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())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function action_view() {
|
||||
list($id,$output) = Table::page(__METHOD__);
|
||||
|
||||
@@ -257,5 +334,24 @@ $(document).ready(function() {
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
|
||||
private function add_edit($id=NULL,$output='') {
|
||||
$so = ORM::factory('Service',$id);
|
||||
|
||||
if ($_POST) {
|
||||
if ($so->values($this->request->post())->changed() AND ! ($this->save($so)))
|
||||
$so->reload();
|
||||
|
||||
// Do we have plugin data to save as well
|
||||
if ($this->request->post('plugin') AND $so->loaded()) {
|
||||
$x = $so->plugin();
|
||||
|
||||
if ($x->values(Arr::merge(array('service_id'=>$so->id),$this->request->post('plugin')))->changed())
|
||||
$this->save($x);
|
||||
}
|
||||
}
|
||||
|
||||
return $so;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -29,6 +29,17 @@ class Model_Service extends ORM_OSB {
|
||||
'account'=>array(),
|
||||
);
|
||||
|
||||
// Validation rules
|
||||
public function rules() {
|
||||
$x = Arr::merge(parent::rules(), array(
|
||||
'product_id' => array(
|
||||
array('not_equal', array(':value', array(0))),
|
||||
),
|
||||
));
|
||||
|
||||
return $x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters used to format the display of values into friendlier values
|
||||
*/
|
||||
@@ -50,6 +61,10 @@ class Model_Service extends ORM_OSB {
|
||||
),
|
||||
);
|
||||
|
||||
protected $_nullifempty = array(
|
||||
'price_override',
|
||||
);
|
||||
|
||||
protected $_form = array('id'=>'id','value'=>'service_name()');
|
||||
|
||||
// Cache our calls to our plugins
|
||||
@@ -216,6 +231,13 @@ class Model_Service extends ORM_OSB {
|
||||
return $type ? Model_Service::$plugin[$this->id]->$type : Model_Service::$plugin[$this->id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the plugin to store data
|
||||
*/
|
||||
public function plugin_edit() {
|
||||
return (is_null($x = $this->plugin())) ? NULL : $x->render_edit();
|
||||
}
|
||||
|
||||
public function revenue($annual=FALSE) {
|
||||
$multiple = $annual ? Period::multiple($this->recur_schedule) : 1;
|
||||
|
||||
@@ -243,7 +265,7 @@ class Model_Service extends ORM_OSB {
|
||||
$x = $this->product->keyget('price_group',$this->recur_schedule);
|
||||
|
||||
// @todo This index shouldnt be hard coded.
|
||||
$p = ! is_null($this->price) ? $this->price : $x[$this->price_group]['price_base'];
|
||||
$p = ! is_null($this->price) ? $this->price : (isset($x[$this->price_group]['price_base']) ? $x[$this->price_group]['price_base'] : NULL);
|
||||
|
||||
if (! $original AND ! is_null($this->price_override))
|
||||
$p = $this->price_override;
|
||||
@@ -265,20 +287,13 @@ class Model_Service extends ORM_OSB {
|
||||
return is_null($plugin) ? array() : $plugin->_details($type);
|
||||
|
||||
case 'service_view':
|
||||
return is_null($plugin) ? HTML::nbsp('') : $plugin->service_view();
|
||||
return is_null($plugin) ? HTML::nbsp('') : $plugin->render_view();
|
||||
|
||||
default:
|
||||
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the plugin to store data
|
||||
*/
|
||||
public function admin_update() {
|
||||
return (is_null($plugin = $this->plugin())) ? NULL : $plugin->admin_update();
|
||||
}
|
||||
|
||||
public function transactions() {
|
||||
return $this->invoice_item->order_by('date_start')->order_by('date_stop');
|
||||
}
|
||||
|
@@ -47,14 +47,6 @@ abstract class Model_Service_Plugin extends ORM_OSB {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form info for admins to update
|
||||
*/
|
||||
public function admin_update() {
|
||||
return View::factory(sprintf('service/admin/plugin/%s/edit',$this->plugin()))
|
||||
->set('o',$this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the button that launches the management of this service, generally from a 3rd party
|
||||
*/
|
||||
@@ -96,18 +88,26 @@ function() { $("form[id=id_"+t[0]+"_"+t[1]+"]").submit(); });
|
||||
}
|
||||
|
||||
/**
|
||||
* Show our service name as defined in the DB with product suffix.
|
||||
* Form info for admins to update plugin data
|
||||
*/
|
||||
public function service_name() {
|
||||
return sprintf('%s - %s',$this->service->product->title(),$this->name());
|
||||
public function render_edit() {
|
||||
return View::factory(sprintf('service/admin/plugin/%s/edit',$this->plugin()))
|
||||
->set('o',$this);
|
||||
}
|
||||
|
||||
/**
|
||||
* View details of the service
|
||||
*/
|
||||
public function service_view() {
|
||||
public function render_view() {
|
||||
return View::factory(sprintf('service/user/plugin/%s/view',$this->plugin()))
|
||||
->set('o',$this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show our service name as defined in the DB with product suffix.
|
||||
*/
|
||||
public function service_name() {
|
||||
return sprintf('%s - %s',$this->service->product->title(),$this->name());
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user