Skip to content

Commit

Permalink
added: inline edit plugin takes into account caneditrow plugin options
Browse files Browse the repository at this point in the history
  • Loading branch information
pollen8 committed Apr 29, 2013
1 parent 2878088 commit 0686199
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 12 deletions.
19 changes: 13 additions & 6 deletions components/com_fabrik/views/form/view.raw.php
Expand Up @@ -19,7 +19,7 @@
* @since 3.0
*/

class fabrikViewForm extends JView
class FabrikViewForm extends JView
{

/**
Expand All @@ -42,11 +42,17 @@ public function inlineEdit()
$app = JFactory::getApplication();
$input = $app->input;

// Need to render() with all element ids in case canEditRow plugins etc use the row data.
$elids = $input->get('elementid', array(), 'array');
$input->set('elementid', null);

$form = $model->getForm();
if ($model->render() === false)
{
return false;
}
// Set back to original input so we only show the requested elements
$input->set('elementid', $elids);
$this->groups = $this->get('GroupView');

// Main trigger element's id
Expand Down Expand Up @@ -187,8 +193,8 @@ public function display($tpl = null)
$group = new stdClass;
$groupParams = $groupModel->getParams();
$aElements = array();
//check if group is acutally a table join

// Check if group is acutally a table join
$repeatGroup = 1;
$foreignKey = null;

Expand All @@ -202,8 +208,10 @@ public function display($tpl = null)
if (is_object($joinTable))
{
$foreignKey = $joinTable->table_join_key;
//need to duplicate this perhaps per the number of times
//that a repeat group occurs in the default data?
/*
* Need to duplicate this perhaps per the number of times
* that a repeat group occurs in the default data?
*/
if (isset($model->_data['join']) && array_key_exists($joinTable->id, $model->_data['join']))
{
$elementModels = $groupModel->getPublishedElements();
Expand All @@ -214,7 +222,6 @@ public function display($tpl = null)
}
else
{
//$$$ rob test!!!
if (!$groupModel->canView())
{
continue;
Expand All @@ -224,7 +231,7 @@ public function display($tpl = null)
}
else
{
// repeat groups which arent joins
// Repeat groups which arent joins
$elementModels = $groupModel->getPublishedElements();
foreach ($elementModels as $tmpElement)
{
Expand Down
2 changes: 1 addition & 1 deletion media/com_fabrik/js/list-min.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions media/com_fabrik/js/list.js
Expand Up @@ -506,6 +506,16 @@ var FbList = new Class({
}.bind(this));
this.plugins = a;
},

firePlugin: function (method) {
var args = Array.prototype.slice.call(arguments);
args = args.slice(1, args.length);
this.plugins.each(function (plugin) {
console.log('list fire event ', method, this, args);
Fabrik.fireEvent(method, [this, args]);
}.bind(this));
return this.result === false ? false : true;
},

watchEmpty: function (e) {
var b = document.id(this.options.form).getElement('.doempty', this.options.form);
Expand Down
1 change: 1 addition & 0 deletions plugins/fabrik_list/caneditrow/caneditrow-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions plugins/fabrik_list/caneditrow/caneditrow.js
@@ -0,0 +1,15 @@
var FbListCanEditRow = new Class({
Extends: FbListPlugin,

initialize: function (options) {
this.parent(options);
Fabrik.addEvent('onCanEditRow', function (list, args) {
this.onCanEditRow(list, args);
}.bind(this));
},

onCanEditRow: function (list, rowid) {
rowid = rowid[0];
list.result = this.options.acl[rowid];
}
});
34 changes: 31 additions & 3 deletions plugins/fabrik_list/caneditrow/caneditrow.php
Expand Up @@ -26,6 +26,7 @@
class PlgFabrik_ListCaneditrow extends PlgFabrik_List
{

protected $acl = array();
/**
* Can the plug-in select list rows
*
Expand All @@ -49,7 +50,8 @@ public function canSelectRows()

public function onCanEdit($params, $listModel, $row)
{
// If $row is null, we were called from the table's canEdit() in a per-table rather than per-row context,

// If $row is null, we were called from the list's canEdit() in a per-table rather than per-row context,
// and we don't have an opinion on per-table edit permissions, so just return true.
if (is_null($row) || is_null($row[0]))
{
Expand All @@ -71,6 +73,7 @@ public function onCanEdit($params, $listModel, $row)
// $$$ rob if no can edit field selected in admin return true
if (trim($field) == '' && trim($caneditrow_eval) == '')
{
$this->acl[$data->__pk_val] = true;
return true;
}

Expand All @@ -81,6 +84,7 @@ public function onCanEdit($params, $listModel, $row)
$caneditrow_eval = $w->parseMessageForPlaceHolder($caneditrow_eval, $data);
$caneditrow_eval = @eval($caneditrow_eval);
FabrikWorker::logEval($caneditrow_eval, 'Caught exception on eval in can edit row : %s');
$this->acl[$data->__pk_val] = $caneditrow_eval;
return $caneditrow_eval;
}
else
Expand All @@ -96,10 +100,14 @@ public function onCanEdit($params, $listModel, $row)
{
case '=':
default:
return $data->$field == $value;
$return = $data->$field == $value;
$this->acl[$data->__pk_val] = $return;
return $return;
break;
case "!=":
return $data->$field != $value;
$return = $data->$field != $value;
$this->acl[$data->__pk_val] = $return;
return $return;
break;
}

Expand All @@ -116,4 +124,24 @@ protected function getAclParam()
{
return 'caneditrow_access';
}

/**
* Return the javascript to create an instance of the class defined in formJavascriptClass
*
* @param object $params plugin parameters
* @param object $model list model
* @param array $args array [0] => string table's form id to contain plugin
*
* @return bool
*/

public function onLoadJavascriptInstance($params, $model, $args)
{
parent::onLoadJavascriptInstance($params, $model, $args);
$opts = $this->getElementJSOptions($model);
$opts->acl = $this->acl;
$opts = json_encode($opts);
$this->jsInstance = "new FbListCanEditRow($opts)";
return true;
}
}
2 changes: 2 additions & 0 deletions plugins/fabrik_list/caneditrow/caneditrow.xml
Expand Up @@ -12,6 +12,8 @@
<description>PLG_LIST_CANEDITROW_DESCRIPTION</description>
<files>
<filename plugin="caneditrow">caneditrow.php</filename>
<filename>caneditrow.js</filename>
<filename>caneditrow-min.js</filename>
<filename>index.html</filename>
<folder>forms</folder>
<folder>language</folder>
Expand Down
2 changes: 1 addition & 1 deletion plugins/fabrik_list/inlineedit/inlineedit-min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion plugins/fabrik_list/inlineedit/inlineedit.js
Expand Up @@ -289,7 +289,9 @@ var FbListInlineEdit = new Class({
if (cell.hasClass('fabrik_uneditable') || cell.hasClass('fabrik_ordercell') || cell.hasClass('fabrik_select') || cell.hasClass('fabrik_actions')) {
return false;
}
return true;
var rowid = this.getRowId(cell.getParent('.fabrik_row'));
res = this.getList().firePlugin('onCanEditRow', rowid);
return res;
},

getPreviousEditable: function (active) {
Expand Down

0 comments on commit 0686199

Please sign in to comment.