diff --git a/app/Controller/DecayingModelController.php b/app/Controller/DecayingModelController.php index 902be881f..b6c6874b9 100644 --- a/app/Controller/DecayingModelController.php +++ b/app/Controller/DecayingModelController.php @@ -386,7 +386,8 @@ class DecayingModelController extends AppController public function getAllDecayingModels() { if ($this->request->is('get') && $this->request->is('ajax')) { - $savedDecayingModels = $this->DecayingModel->fetchAllAllowedModels($this->Auth->user()); + $filters = $this->request->query; + $savedDecayingModels = $this->DecayingModel->fetchAllAllowedModels($this->Auth->user(), true, $filters); $associated_models = $this->DecayingModel->DecayingModelMapping->getAssociatedModels($this->Auth->user()); $associated_types = array(); foreach ($associated_models as $type => $models) { diff --git a/app/Model/DecayingModel.php b/app/Model/DecayingModel.php index 5badb34e9..b24a3a21e 100644 --- a/app/Model/DecayingModel.php +++ b/app/Model/DecayingModel.php @@ -167,7 +167,7 @@ class DecayingModel extends AppModel return !is_null($decaying_model['DecayingModel']['uuid']); } - public function fetchAllAllowedModels($user, $full=true) + public function fetchAllAllowedModels($user, $full=true, $filters=array()) { $conditions = array(); if (!$user['Role']['perm_site_admin']) { @@ -176,6 +176,13 @@ class DecayingModel extends AppModel 'all_orgs' => 1 ); } + if (!empty($filters)) { + if (isset($filters['my_models']) && $filters['my_models']) { + $conditions[] = array('DecayingModel.org_id' => $user['Organisation']['id']); + } elseif (isset($filters['default_models']) && $filters['default_models']) { + $conditions[] = array('not' => array('DecayingModel.uuid' => null)); + } + } $decayingModels = $this->find('all', array( 'conditions' => $conditions, 'include' => $full ? 'DecayingModelMapping' :'' diff --git a/app/View/DecayingModel/decaying_tool.ctp b/app/View/DecayingModel/decaying_tool.ctp index 97a28185f..b4f2f7725 100644 --- a/app/View/DecayingModel/decaying_tool.ctp +++ b/app/View/DecayingModel/decaying_tool.ctp @@ -138,6 +138,17 @@
+ + + + + diff --git a/app/webroot/css/decayingTool.css b/app/webroot/css/decayingTool.css index 7e6060a4e..0f657c7df 100644 --- a/app/webroot/css/decayingTool.css +++ b/app/webroot/css/decayingTool.css @@ -163,3 +163,14 @@ svg text.axis-label { font: 10px sans-serif; fill: #999; } + +.tableRadioFilterOptionsContainer { + display: inline-block; + padding: 0 5px; + margin-left: 10px; + border-top: 1px solid #ddd; + border-left: 1px solid #ddd; + border-right: 1px solid #ddd; + border-top-left-radius: 4px; + border-top-right-radius: 4px; +} \ No newline at end of file diff --git a/app/webroot/js/decayingTool.js b/app/webroot/js/decayingTool.js index 5bd5cdfcc..1e78ac2aa 100644 --- a/app/webroot/js/decayingTool.js +++ b/app/webroot/js/decayingTool.js @@ -24,9 +24,7 @@ selection_history2: [] }; this.model_table = new ModelTable(); - $.getJSON('/decayingModel/getAllDecayingModels/', function(json) { - that.model_table.update(json); - }); + this.model_table.refreshTable(); this._init(); }; @@ -889,6 +887,12 @@ ModelTable.prototype = { ]; this.data = []; this.thead.html(this._get_html_header(this.table_header)); + + // bind listener on radio filters + var that = this; + $('.tableRadioFilterOptionsContainer input[type=\'radio\']').change(function() { + that.refreshTable(); + }); }, update: function(data) { @@ -897,6 +901,18 @@ ModelTable.prototype = { this._draw(); }, + refreshTable: function(data) { + var that = this; + var $filter_radio = $('.tableRadioFilterOptionsContainer input[type=\'radio\']:checked'); + var filters = {}; + if ($filter_radio) { + filters[$filter_radio.val()] = 1; + } + $.getJSON('/decayingModel/getAllDecayingModels/', filters, function(json) { + that.update(json); + }); + }, + massage_data: function(data) { var massaged_data = $.extend([], data);