LSldapObject / Custom actions : Added ajax validation feature
authorBenjamin Renard <brenard@easter-eggs.com>
Fri, 20 May 2011 13:56:19 +0000 (15:56 +0200)
committerBenjamin Renard <brenard@easter-eggs.com>
Fri, 20 May 2011 13:57:00 +0000 (15:57 +0200)
public_html/includes/class/class.LSform.php
public_html/includes/js/LSview.js
public_html/templates/default/view.tpl
public_html/view.php

index 1651c98..b33e87e 100644 (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(),
index d8ff8b5..666e746 100644 (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';
     }
 
 });
index 037ce13..b73dc62 100644 (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>
index 34927ea..b5be65a 100644 (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'
                   );
                 }
               }