Fix: edit of percentage

Conflicts:
	htdocs/comm/action/fiche.php
This commit is contained in:
Laurent Destailleur 2012-09-02 14:27:00 +02:00
parent d12700aeab
commit a7d6289d4b
2 changed files with 183 additions and 155 deletions

View File

@ -85,13 +85,14 @@ if ($action == 'add_action')
} }
$fulldayevent=$_POST["fullday"]; $fulldayevent=$_POST["fullday"];
$percentage=in_array(GETPOST('status'),array(-1,100))?GETPOST('status'):GETPOST("percentage"); // If status is -1 or 100, percentage is not defined and we must use status
// Clean parameters // Clean parameters
$datep=dol_mktime($fulldayevent?'00':$_POST["aphour"], $fulldayevent?'00':$_POST["apmin"], 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $datep=dol_mktime($fulldayevent?'00':$_POST["aphour"], $fulldayevent?'00':$_POST["apmin"], 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]);
$datef=dol_mktime($fulldayevent?'23':$_POST["p2hour"], $fulldayevent?'59':$_POST["p2min"], $fulldayevent?'59':'0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); $datef=dol_mktime($fulldayevent?'23':$_POST["p2hour"], $fulldayevent?'59':$_POST["p2min"], $fulldayevent?'59':'0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]);
// Check parameters // Check parameters
if (! $datef && $_POST["percentage"] == 100) if (! $datef && $percentage == 100)
{ {
$error++; $error++;
$action = 'create'; $action = 'create';
@ -135,7 +136,7 @@ if ($action == 'add_action')
$actioncomm->fk_project = isset($_POST["projectid"])?$_POST["projectid"]:0; $actioncomm->fk_project = isset($_POST["projectid"])?$_POST["projectid"]:0;
$actioncomm->datep = $datep; $actioncomm->datep = $datep;
$actioncomm->datef = $datef; $actioncomm->datef = $datef;
$actioncomm->percentage = isset($_POST["percentage"])?$_POST["percentage"]:0; $actioncomm->percentage = $percentage;
$actioncomm->duree=(($_POST["dureehour"] * 60) + $_POST["dureemin"]) * 60; $actioncomm->duree=(($_POST["dureehour"] * 60) + $_POST["dureemin"]) * 60;
$usertodo=new User($db); $usertodo=new User($db);
@ -257,21 +258,20 @@ if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
} }
/* /*
* Action mise a jour de l'action * Action update event
*/ */
if ($action == 'update') if ($action == 'update')
{ {
if (! $_POST["cancel"]) if (! $_POST["cancel"])
{ {
$fulldayevent=$_POST["fullday"]; $fulldayevent=$_POST["fullday"];
$percentage=in_array(GETPOST('status'),array(-1,100))?GETPOST('status'):GETPOST("percentage"); // If status is -1 or 100, percentage is not defined and we must use status
// Clean parameters // Clean parameters
if ($_POST["aphour"] == -1) $_POST["aphour"]='0'; if ($_POST["aphour"] == -1) $_POST["aphour"]='0';
if ($_POST["apmin"] == -1) $_POST["apmin"]='0'; if ($_POST["apmin"] == -1) $_POST["apmin"]='0';
if ($_POST["p2hour"] == -1) $_POST["p2hour"]='0'; if ($_POST["p2hour"] == -1) $_POST["p2hour"]='0';
if ($_POST["p2min"] == -1) $_POST["p2min"]='0'; if ($_POST["p2min"] == -1) $_POST["p2min"]='0';
//if ($_POST["adhour"] == -1) $_POST["adhour"]='0';
//if ($_POST["admin"] == -1) $_POST["admin"]='0';
$actioncomm = new Actioncomm($db); $actioncomm = new Actioncomm($db);
$actioncomm->fetch($id); $actioncomm->fetch($id);
@ -282,9 +282,7 @@ if ($action == 'update')
$actioncomm->label = $_POST["label"]; $actioncomm->label = $_POST["label"];
$actioncomm->datep = $datep; $actioncomm->datep = $datep;
$actioncomm->datef = $datef; $actioncomm->datef = $datef;
//$actioncomm->date = $datea; $actioncomm->percentage = $percentage;
//$actioncomm->dateend = $datea2;
$actioncomm->percentage = $_POST["percentage"];
$actioncomm->priority = $_POST["priority"]; $actioncomm->priority = $_POST["priority"];
$actioncomm->fulldayevent= $_POST["fullday"]?1:0; $actioncomm->fulldayevent= $_POST["fullday"]?1:0;
$actioncomm->location = isset($_POST["location"])?$_POST["location"]:''; $actioncomm->location = isset($_POST["location"])?$_POST["location"]:'';
@ -294,7 +292,7 @@ if ($action == 'update')
$actioncomm->note = $_POST["note"]; $actioncomm->note = $_POST["note"];
$actioncomm->pnote = $_POST["note"]; $actioncomm->pnote = $_POST["note"];
if (! $datef && $_POST["percentage"] == 100) if (! $datef && $percentage == 100)
{ {
$error=$langs->trans("ErrorFieldRequired",$langs->trans("DateEnd")); $error=$langs->trans("ErrorFieldRequired",$langs->trans("DateEnd"));
$action = 'edit'; $action = 'edit';

View File

@ -1,32 +1,32 @@
<?php <?php
/* Copyright (c) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (c) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* \file htdocs/core/class/html.formactions.class.php * \file htdocs/core/class/html.formactions.class.php
* \ingroup core * \ingroup core
* \brief Fichier de la classe des fonctions predefinie de composants html actions * \brief Fichier de la classe des fonctions predefinie de composants html actions
*/ */
/** /**
* Class to manage building of HTML components * Class to manage building of HTML components
*/ */
class FormActions class FormActions
{ {
var $db; var $db;
@ -49,7 +49,7 @@ class FormActions
* Show list of action status * Show list of action status
* *
* @param string $formname Name of form where select in included * @param string $formname Name of form where select in included
* @param string $selected Preselected value * @param string $selected Preselected value (-1..100)
* @param int $canedit 1=can edit, 0=read only * @param int $canedit 1=can edit, 0=read only
* @param string $htmlname Name of html prefix for html fields (selectX and valX) * @param string $htmlname Name of html prefix for html fields (selectX and valX)
* @return void * @return void
@ -58,39 +58,69 @@ class FormActions
{ {
global $langs,$conf; global $langs,$conf;
$listofstatus=array('-1'=>$langs->trans("ActionNotApplicable"), $listofstatus = array(
'0'=>$langs->trans("ActionRunningNotStarted"), '-1' => $langs->trans("ActionNotApplicable"),
'50'=>$langs->trans("ActionRunningShort"), '0' => $langs->trans("ActionRunningNotStarted"),
'100'=>$langs->trans("ActionDoneShort")); '50' => $langs->trans("ActionRunningShort"),
'100' => $langs->trans("ActionDoneShort")
);
if ($conf->use_javascript_ajax) if (! empty($conf->use_javascript_ajax))
{ {
print "\n"; print "\n";
print '<script type="text/javascript">'."\n"; print "<script type=\"text/javascript\">
print 'jQuery(document).ready(function () {'."\n"; var htmlname = '".$htmlname."';
print 'jQuery("#select'.$htmlname.'").change(function() { select_status(document.'.$formname.'.status.value); });'."\n";
print 'jQuery("#val'.$htmlname.'").change(function() { select_status(jQuery("#val'.$htmlname.'").val()); });'."\n"; $(document).ready(function () {
print 'select_status(document.'.$formname.'.status.value);'."\n"; select_status();
print '});'."\n";
print 'function select_status(mypercentage) {'."\n"; $('#select' + htmlname).change(function() {
print 'document.'.$formname.'.percentageshown.value=(mypercentage>=0?mypercentage:\'\');'."\n"; select_status();
print 'document.'.$formname.'.percentage.value=mypercentage;'."\n"; });
print 'if (mypercentage == -1) { document.'.$formname.'.percentageshown.disabled=true; jQuery(".hideifna").hide(); }'."\n"; // FIXME use another method for update combobox
print 'else if (mypercentage == 0) { document.'.$formname.'.percentageshown.disabled=true; jQuery(".hideifna").show();}'."\n"; //$('#val' + htmlname).change(function() {
print 'else if (mypercentage == 100) { document.'.$formname.'.percentageshown.disabled=true; jQuery(".hideifna").show();}'."\n"; //select_status();
print 'else { document.'.$formname.'.percentageshown.disabled=false; jQuery(".hideifna").show();}'."\n"; //});
print '}'."\n"; });
print '</script>'."\n";
function select_status() {
var defaultvalue = $('#select' + htmlname).val();
var percentage = $('input[name=percentage]');
var selected = '".(isset($selected)?$selected:'')."';
var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
percentage.val(value);
if (defaultvalue == -1) {
percentage.attr('disabled', 'disabled');
$('.hideifna').hide();
}
else if (defaultvalue == 0) {
percentage.val(0);
percentage.attr('disabled', 'disabled');
$('.hideifna').show();
}
else if (defaultvalue == 100) {
percentage.val(100);
percentage.attr('disabled', 'disabled');
$('.hideifna').show();
}
else {
if (defaultvalue == 50 && (percentage.val() == 0 || percentage.val() == 100)) { percentage.val(50) };
percentage.removeAttr('disabled');
$('.hideifna').show();
}
}
</script>\n";
print '<select '.($canedit?'':'disabled="disabled" ').'name="status" id="select'.$htmlname.'" class="flat">'; print '<select '.($canedit?'':'disabled="disabled" ').'name="status" id="select'.$htmlname.'" class="flat">';
foreach($listofstatus as $key => $val) foreach($listofstatus as $key => $val)
{ {
print '<option value="'.$key.'"'.($selected == $key?' selected="selected"':'').'>'.$val.'</option>'; print '<option value="'.$key.'"'.(($selected == $key) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected="selected"' : '').'>'.$val.'</option>';
} }
print '</select>'; print '</select>';
if ($selected == 0 || $selected == 100) $canedit=0; if ($selected == 0 || $selected == 100) $canedit=0;
print ' <input type="text" id="val'.$htmlname.'" name="percentageshown" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled="disabled"').'>'; print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled="disabled"').'>';
print '<span class="hideifna">%</span>'; print '<span class="hideifna">%</span>';
print ' <input type="hidden" name="percentage" value="'.$selected.'">';
} }
else else
{ {