mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +01:00
Support for admin-ui event triggers. Plugin-builder example added.
This commit is contained in:
parent
d633455c73
commit
00a516b0d3
@ -2164,7 +2164,7 @@ class pluginBuilder
|
||||
function __construct()
|
||||
{
|
||||
$this->special['checkboxes'] = array('title'=> '','type' => null, 'data' => null, 'width'=>'5%', 'thclass' =>'center', 'forced'=> TRUE, 'class'=>'center', 'toggle' => 'e-multiselect', 'fieldpref'=>true);
|
||||
$this->special['options'] = array( 'title'=> LAN_OPTIONS, 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE, 'fieldpref'=>true);
|
||||
$this->special['options'] = array( 'title'=> 'LAN_OPTIONS', 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE, 'fieldpref'=>true);
|
||||
|
||||
if(vartrue($_GET['newplugin']))
|
||||
{
|
||||
@ -3372,12 +3372,24 @@ $text .= "
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
foreach($vars['fields'] as $key=>$val)
|
||||
{
|
||||
if($val['type'] == 'image' && empty($val['readParms']))
|
||||
{
|
||||
$vars['fields'][$key]['readParms'] = 'thumb=80x80'; // provide a thumbnail preview by default.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$FIELDS = str_replace($srch,$repl,var_export($vars['fields'],true));
|
||||
$FIELDS = preg_replace("#('([A-Z0-9_]*?LAN[_A-Z0-9]*)')#","$2",$FIELDS); // remove quotations from LANs.
|
||||
$FIELDPREF = array();
|
||||
|
||||
foreach($vars['fields'] as $k=>$v)
|
||||
{
|
||||
|
||||
if(isset($v['fieldpref']) && $k != 'checkboxes' && $k !='options')
|
||||
{
|
||||
$FIELDPREF[] = "'".$k."'";
|
||||
@ -3392,6 +3404,7 @@ class ".$table." extends e_admin_ui
|
||||
|
||||
protected \$pluginTitle = '".$pluginTitle."';
|
||||
protected \$pluginName = '".$vars['pluginName']."';
|
||||
// protected \$eventName = '".$vars['pluginName']."-".$vars['table']."'; // remove comment to enable event triggers in admin.
|
||||
protected \$table = '".$vars['table']."';
|
||||
protected \$pid = '".$vars['pid']."';
|
||||
protected \$perPage = 10;
|
||||
|
@ -59,11 +59,13 @@ class generic_ui extends e_admin_ui
|
||||
|
||||
protected $pluginTitle = WMLAN_00;
|
||||
protected $pluginName = 'core';
|
||||
protected $eventName = 'wmessage';
|
||||
protected $table = 'generic';
|
||||
protected $pid = 'gen_id';
|
||||
protected $perPage = 10;
|
||||
protected $batchDelete = true;
|
||||
protected $batchCopy = true;
|
||||
|
||||
// protected $sortField = 'somefield_order';
|
||||
// protected $orderStep = 10;
|
||||
// protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable.
|
||||
|
@ -2324,6 +2324,13 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
* @var string plugin name
|
||||
*/
|
||||
protected $pluginName;
|
||||
|
||||
|
||||
/**
|
||||
* @var string event name
|
||||
* base event trigger name to be used. Leave blank for no trigger.
|
||||
*/
|
||||
protected $eventName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@ -2476,6 +2483,15 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
return $this->batchFeaturebox;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEventName()
|
||||
{
|
||||
return $this->eventName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
@ -2493,6 +2509,8 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
return deftrue($this->pluginTitle, $this->pluginTitle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Tab data
|
||||
* @return array
|
||||
@ -3924,6 +3942,8 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
// Scenario I - use request owned POST data - toForm already executed
|
||||
$model->setPostedData($_posted, null, false, false)
|
||||
->save(true);
|
||||
|
||||
|
||||
// Scenario II - inner model sanitize
|
||||
//$this->getModel()->setPosted($this->convertToData($_POST, null, false, true);
|
||||
|
||||
@ -3931,9 +3951,19 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
if(!$this->getModel()->hasError())
|
||||
{
|
||||
// callback (if any)
|
||||
$new_data = $model->getData();
|
||||
$id = $model->getId();
|
||||
|
||||
// Trigger Admin-ui event.
|
||||
if($triggerName = $this->getEventTriggerName($_posted['etrigger_submit']))
|
||||
{
|
||||
e107::getMessage()->addDebug('Admin-ui Trigger: '.$triggerName);
|
||||
e107::getEvent()->trigger($triggerName, array('newData'=>$new_data,'oldData'=>$old_data,'id'=> $id));
|
||||
}
|
||||
|
||||
if($callbackAfter && method_exists($this, $callbackAfter))
|
||||
{
|
||||
$this->$callbackAfter($model->getData(), $old_data, $model->getId());
|
||||
$this->$callbackAfter($new_data, $old_data, $id);
|
||||
}
|
||||
$model->setMessages(true); //FIX - move messages (and session messages) to the default stack
|
||||
$this->doAfterSubmit($model->getId(), $noredirectAction);
|
||||
@ -3954,6 +3984,19 @@ class e_admin_controller_ui extends e_admin_controller
|
||||
$model->setMessages();
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Return a custom event trigger name
|
||||
*/
|
||||
public function getEventTriggerName($type=null)
|
||||
{
|
||||
if(!$plug = $this->getEventName() || empty($type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return 'admin-'.strtolower($plug).'-'.strtolower($type);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class e_admin_ui extends e_admin_controller_ui
|
||||
@ -4594,6 +4637,14 @@ class e_admin_ui extends e_admin_controller_ui
|
||||
if($this->beforeDelete($data, $id))
|
||||
{
|
||||
$check = $this->getTreeModel()->delete($id);
|
||||
|
||||
if($triggerName = $this->getEventTriggerName('delete'))
|
||||
{
|
||||
e107::getMessage()->addDebug('Admin-ui Trigger: '.$triggerName);
|
||||
e107::getEvent()->trigger($triggerName, array('newData'=>$data,'oldData'=>$data,'id'=> $id));
|
||||
}
|
||||
|
||||
|
||||
if($this->afterDelete($data, $id, $check))
|
||||
{
|
||||
$this->getTreeModel()->setMessages();
|
||||
|
Loading…
x
Reference in New Issue
Block a user