LSldapObject / Custom actions : Added ajax validation feature

This commit is contained in:
Benjamin Renard 2011-05-20 15:56:19 +02:00
parent 5d6ac6956c
commit 97a2713ea0
4 changed files with 59 additions and 7 deletions

View file

@ -83,7 +83,7 @@ class LSform {
*/
function display(){
if ($this -> idForm == 'view') {
self :: loadDependenciesDisplayView();
self :: loadDependenciesDisplayView($this -> $ldapObject);
}
else {
LSsession :: addJSscript('LSformElement_field.js');
@ -188,14 +188,35 @@ class LSform {
*
* @retval void
*/
public static function loadDependenciesDisplayView() {
public static function loadDependenciesDisplayView($ldapObject=false) {
LSsession :: addCssFile('LSform.css');
LSsession :: addJSscript('LSform.js');
LSsession :: addJSconfigParam('LSview_labels', array(
$customActionLabels = array ();
if (is_a($ldapObject,'LSldapObject')) {
$objectname=$ldapObject -> getDisplayName();
$customActionsConfig = LSconfig :: get('LSobjects.'.$ldapObject->type_name.'.customActions');
if (is_array($customActionsConfig)) {
foreach($customActionsConfig as $name => $config) {
if (isset($config['question_format'])) {
$customActionLabels['custom_action_'.$name.'_confirm_text'] = getFData(__($config['question_format']),$objectname);
}
else {
$customActionLabels['custom_action_'.$name.'_confirm_text'] = getFData(
_('Do you really want to execute custom action %{customAction} on %{objectname} ?'),
array(
'objectname' => $objectname,
'customAction' => $name
)
);
}
}
}
}
LSsession :: addJSconfigParam('LSview_labels', array_merge(array(
'delete_confirm_text' => _("Do you really want to delete"),
'delete_confirm_title' => _("Caution"),
'delete_confirm_validate' => _("Delete")
));
),$customActionLabels));
if (LSsession :: loadLSclass('LSconfirmBox')) {
LSconfirmBox :: loadDependenciesDisplay();
}
@ -210,7 +231,7 @@ class LSform {
* @retval void
*/
function displayView(){
self :: loadDependenciesDisplayView();
self :: loadDependenciesDisplayView($this -> ldapObject);
$LSform_object = array(
'type' => $this -> ldapObject -> getType(),

View file

@ -95,6 +95,36 @@ var LSview = new Class({
removeFromA: function(a) {
document.location = a.href+'&valid';
},
onCustomActionBtnClick: function(event,a) {
Event(event).stop();
if (!this._confirmBoxOpen) {
this._confirmBoxOpen = 1;
var getName = new RegExp('customAction=([^&]*)');
var name = getName.exec(a.href)[1];
if (name) {
var title = a.innerHTML;
if ($type(this.labels['custom_action_'+name+'_confirm_text'])) {
var text = this.labels['custom_action_'+name+'_confirm_text']
}
else {
var objectname = $('LSview_title').innerHTML;
var text = getFData('Do you really want to execute custom action %{customAction} on %{objectname} ?',{customAction: name, objectname: objectname });
}
this.confirmBox = new LSconfirmBox({
text: text,
title: title,
startElement: a,
onConfirm: this.executeCustomActionFromA.bind(this,a),
onClose: this.onConfirmBoxClose.bind(this)
});
}
}
},
executeCustomActionFromA: function(a) {
document.location = a.href+'&valid';
}
});

View file

@ -4,7 +4,7 @@
<ul class='LSview-actions'>
{foreach from=$LSview_actions item=item}
{if is_array($item)}
<li class='LSview-actions'><a href='{$item.url}' class='LSview-actions' ><img src='{$LS_IMAGES_DIR}/{$item.action}.png' alt='{$item.label}' title='{$item.label}' /> {$item.label}</a></li>
<li class='LSview-actions'><a href='{$item.url}' class='LSview-actions{if $item.class} {$item.class}{/if}' ><img src='{$LS_IMAGES_DIR}/{$item.action}.png' alt='{$item.label}' title='{$item.label}' /> {$item.label}</a></li>
{/if}
{/foreach}
</ul>

View file

@ -70,7 +70,8 @@ if(LSsession :: startLSsession()) {
$LSview_actions[] = array (
'label' => ((isset($config['label']))?__($config['label']):__($name)),
'url' => 'custom_action.php?LSobject='.$LSobject.'&amp;dn='.$dn.'&amp;customAction='.$name,
'action' => ((isset($config['icon']))?$config['icon']:'generate')
'action' => ((isset($config['icon']))?$config['icon']:'generate'),
'class' => 'LScustomActions'
);
}
}