浏览代码

Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

Laurent Destailleur 11 年之前
父节点
当前提交
6e0e812531

+ 4 - 7
htdocs/core/ajax/productonoff.php → htdocs/core/ajax/objectonoff.php

@@ -32,9 +32,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
 $action=GETPOST('action','alpha');
 $id=GETPOST('id', 'int');
 $value=GETPOST('value', 'int');
+$field=GETPOST('field', 'alpha');
+$element=GETPOST('element', 'alpha');
 
 $object = new GenericObject($db);
-
 /*
  * View
  */
@@ -44,9 +45,5 @@ top_httphead();
 print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
 
 // Registering new values
-if (! empty($action) && ! empty($id) && $user->rights->produit->creer) {
-    if ($action == 'setstatus') 
-        $object->setValueFrom('tosell', $value, 'product', $id);
-    else if ($action == 'setstatus_buy') 
-        $object->setValueFrom('tobuy', $value, 'product', $id);
-}
+if (($action == 'set') && ! empty($id))
+    $object->setValueFrom($field, $value, $element, $id);

+ 27 - 29
htdocs/core/lib/ajax.lib.php

@@ -460,35 +460,36 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0,
 }
 
 /**
- *  On/off button for product tosell or tobuy
+ *  On/off button for object
  *
- *  @param  int     $id         Id product to set
- *  @param  string  $code       Name of constant : status or status_buy
+ *  @param  int     $object     Id product to set
+ *  @param  string  $code       Name of constant : status or status_buy for product by example
+ *  @param  string  $field      Name of database field : tosell or tobuy for product by example
+ *  @param  string  $text_on    Text if on
+ *  @param  string  $text_off   Text if off
  *  @param  array   $input      Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid'))
  *  @return void
  */
-function ajax_productonoff($id, $code, $input=array())
+function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input=array())
 {
-    require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
-    global $conf, $langs, $db;
-
-    $object = new Product($db);
-    $object->fetch($id);
+    global $langs;
 
     $out= '<script type="text/javascript">
         $(function() {
             var input = '.json_encode($input).';
 
             // Set constant
-            $("#set_'.$code.'").click(function() {
-                $.get( "'.DOL_URL_ROOT.'/core/ajax/productonoff.php", {
-                    action: \'set'.$code.'\',
+            $("#set_'.$code.'_'.$object->id.'").click(function() {
+                $.get( "'.DOL_URL_ROOT.'/core/ajax/objectonoff.php", {
+                    action: \'set\',
+                    field: \''.$field.'\',
                     value: \'1\',
-                    id: \''.$id.'\'
+                    element: \''.$object->element.'\',
+                    id: \''.$object->id.'\'
                 },
                 function() {
-                    $("#set_'.$code.'").hide();
-                    $("#del_'.$code.'").show();
+                    $("#set_'.$code.'_'.$object->id.'").hide();
+                    $("#del_'.$code.'_'.$object->id.'").show();
                     // Enable another element
                     if (input.disabled && input.disabled.length > 0) {
                         $.each(input.disabled, function(key,value) {
@@ -508,15 +509,17 @@ function ajax_productonoff($id, $code, $input=array())
             });
 
             // Del constant
-            $("#del_'.$code.'").click(function() {
-                $.get( "'.DOL_URL_ROOT.'/core/ajax/productonoff.php", {
-                    action: \'set'.$code.'\',
+            $("#del_'.$code.'_'.$object->id.'").click(function() {
+                $.get( "'.DOL_URL_ROOT.'/core/ajax/objectonoff.php", {
+                    action: \'set\',
+                    field: \''.$field.'\',
                     value: \'0\',
-                    id: \''.$id.'\'
+                    element: \''.$object->element.'\',
+                    id: \''.$object->id.'\'
                 },
                 function() {
-                    $("#del_'.$code.'").hide();
-                    $("#set_'.$code.'").show();
+                    $("#del_'.$code.'_'.$object->id.'").hide();
+                    $("#set_'.$code.'_'.$object->id.'").show();
                     // Disable another element
                     if (input.disabled && input.disabled.length > 0) {
                         $.each(input.disabled, function(key,value) {
@@ -536,14 +539,9 @@ function ajax_productonoff($id, $code, $input=array())
             });
         });
     </script>';
-    if ($code=='status') {
-        $out.= '<span id="set_'.$code.'" class="linkobject '.($object->$code==1?'hideobject':'').'">'.img_picto($langs->trans("ProductStatusNotOnSell"),'switch_off').'</span>';
-        $out.= '<span id="del_'.$code.'" class="linkobject '.($object->$code==1?'':'hideobject').'">'.img_picto($langs->trans("ProductStatusOnSell"),'switch_on').'</span>';
-    }
-    if ($code=='status_buy') {
-    $out.= '<span id="set_'.$code.'" class="linkobject '.($object->$code==1?'hideobject':'').'">'.img_picto($langs->trans("ProductStatusNotOnBuy"),'switch_off').'</span>';
-    $out.= '<span id="del_'.$code.'" class="linkobject '.($object->$code==1?'':'hideobject').'">'.img_picto($langs->trans("ProductStatusOnBuy"),'switch_on').'</span>';
-    }
+    $out.= '<span id="set_'.$code.'_'.$object->id.'" class="linkobject '.($object->$code==1?'hideobject':'').'">'.img_picto($langs->trans($text_off),'switch_off').'</span>';
+    $out.= '<span id="del_'.$code.'_'.$object->id.'" class="linkobject '.($object->$code==1?'':'hideobject').'">'.img_picto($langs->trans($text_on),'switch_on').'</span>';
+
     return $out;
 }
 

+ 12 - 8
htdocs/product/card.php

@@ -1420,7 +1420,7 @@ else
             // Status (to sell)
             print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="2">';
             if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
-                print ajax_productonoff($object->id, 'status');
+                print ajax_object_onoff($object, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
             } else {
                 print $object->getLibStatut(2,0);
             }
@@ -1429,18 +1429,22 @@ else
             // Status (to buy)
             print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="2">';
             if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
-                print ajax_productonoff($object->id, 'status_buy');
+                print ajax_object_onoff($object, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
             } else {
                 print $object->getLibStatut(2,1);
             }
             print '</td></tr>';
 
-			// Batch number management (to batch)
-			if ($conf->productbatch->enabled) {
-				print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Lot").')</td><td colspan="2">';
-				print $object->getLibStatut(2,2);
-				print '</td></tr>';
-			}
+            // Batch number management (to batch)
+            if ($conf->productbatch->enabled) {
+                print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Lot").')</td><td colspan="2">';
+                if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
+                    print ajax_object_onoff($object, 'status_batch', 'tobatch', 'ProductStatusOnBatch', 'ProductStatusNotOnBatch');
+                } else {
+                    print $object->getLibStatut(2,2);
+                }
+                print '</td></tr>';
+            }
 
             // Description
             print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="2">'.(dol_textishtml($object->description)?$object->description:dol_nl2br($object->description,1,true)).'</td></tr>';

+ 18 - 4
htdocs/product/list.php

@@ -507,11 +507,25 @@ else
     				}
     			}
 
-    			// Status (to buy)
-    			print '<td align="center" class="nowrap">'.$product_static->LibStatut($objp->tosell,5,0).'</td>';
-
+                $product_static->status_buy = $objp->tobuy;
+                $product_static->status     = $objp->tosell;
                 // Status (to sell)
-                print '<td align="center" class="nowrap">'.$product_static->LibStatut($objp->tobuy,5,1).'</td>';
+                print '<td align="right" nowrap="nowrap">';
+                if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
+                    print ajax_object_onoff($product_static, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
+                } else {
+                    print $product_static->LibStatut($objp->tosell,5,0);
+                }
+                print '</td>';
+
+                // Status (to buy)
+                print '<td align="right" nowrap="nowrap">';
+                if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
+                    print ajax_object_onoff($product_static, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
+                } else {
+                    print $product_static->LibStatut($objp->tobuy,5,1);
+                }
+                print '</td>';
 
                 print '<td>&nbsp;</td>';
 

+ 2 - 2
htdocs/product/stock/product.php

@@ -279,7 +279,7 @@ if ($id > 0 || $ref)
         // Status (to sell)
         print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
         if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
-            print ajax_productonoff($product->id, 'status');
+            print ajax_object_onoff($product, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
         } else {
             print $product->getLibStatut(2,0);
         }
@@ -288,7 +288,7 @@ if ($id > 0 || $ref)
         // Status (to buy)
         print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="2">';
         if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
-            print ajax_productonoff($product->id, 'status_buy');
+            print ajax_object_onoff($product, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
         } else {
             print $product->getLibStatut(2,1);
         }

+ 5 - 1
htdocs/societe/soc.php

@@ -1698,7 +1698,11 @@ else
         // Status
         print '<tr><td>'.$langs->trans("Status").'</td>';
         print '<td colspan="'.(2+(($showlogo || $showbarcode)?0:1)).'">';
-        print $object->getLibStatut(2);
+        if (! empty($conf->use_javascript_ajax) && $user->rights->societe->creer) {
+            print ajax_object_onoff($object, 'status', 'status', 'InActivity', 'ActivityCeased');
+        } else {
+            print $object->getLibStatut(2);
+        }
         print '</td>';
         print $htmllogobar; $htmllogobar='';
         print '</tr>';