Fixes, adding corrections to the validation for the name field in the calendar Edit form

This commit is contained in:
Gustavo Adolfo Cruz Laura
2011-01-04 20:08:48 +00:00
parent 0ba75c263d
commit 598099469e
4 changed files with 36 additions and 7 deletions

View File

@@ -39,10 +39,12 @@ G::LoadClass ( 'calendar' );
$calendarObj = new calendar ( );
if ((isset ( $_GET ['id'] )) && ($_GET ['id'] != "")) {
$fields = $calendarObj->getCalendarInfo ( $CalendarUid );
$fields ['OLD_NAME'] = $fields['CALENDAR_NAME'];
}
if (! (isset ( $fields ['CALENDAR_UID'] ))) { //For a new Calendar
$fields ['CALENDAR_UID'] = $CalendarUid;
$fields ['OLD_NAME'] = '';
//Default Business Hour
$fields ['BUSINESS_DAY'] [1] ['CALENDAR_BUSINESS_DAY'] = 7;
$fields ['BUSINESS_DAY'] [1] ['CALENDAR_BUSINESS_START'] = "09:00";

View File

@@ -39,6 +39,8 @@ switch ($RBAC->userCanAccess('PM_SETUP_ADVANCE'))
}
// validating the fields
$message = array();
$oldName = isset($_POST['oldName'])?$_POST['oldName']:'';
switch ($_POST['action']){
case 'calendarName':
require_once ('classes/model/CalendarDefinition.php');
@@ -50,13 +52,20 @@ switch ($_POST['action']){
$aCalendarDefinitions = end($aCalendars);
// var_dump($aCalendarDefinitions);
foreach($aCalendarDefinitions as $aDefinitions) {
if ($aDefinitions['CALENDAR_NAME']!=$_POST['name']){
$validated = true;
} else {
if (trim($_POST['name'])==''){
$validated = false;
$message = G::loadTranslation('ID_CALENDAR_INVALID_NAME');
break;
}
if ($aDefinitions['CALENDAR_NAME']!=$_POST['name']){
$validated = true;
} else {
if ($aDefinitions['CALENDAR_NAME']!=$oldName) {
$validated = false;
$message = G::loadTranslation('ID_CALENDAR_INVALID_NAME');
break;
}
}
}
break;
case 'calendarDates':

View File

@@ -10,6 +10,9 @@
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr style="display: none;">
<td colspan="2">{$form.CALENDAR_UID}</td>
</tr>
<tbody><tr style="display: none;">
<td colspan="2">{$form.OLD_NAME}</td>
</tr>
<tr>
<td class="FormTitle" colspan="2" align="">{$form.DEFINITION_TITLE}</td>

View File

@@ -4,6 +4,9 @@
<en>Ndar Uid
</en>
</CALENDAR_UID>
<OLD_NAME type="hidden" size='32' maxlength='32' >
</OLD_NAME>
<DEFINITION_TITLE type="title" enablehtml="0">
<en><![CDATA[Calendar Definition]]></en>
</DEFINITION_TITLE>
@@ -16,6 +19,7 @@
<CALENDAR_STATUS type="checkbox" value="ACTIVE" falsevalue="INACTIVE" defaultvalue="ACTIVE" labelonright="1" enablehtml="0">
<en><![CDATA[Active]]></en>
</CALENDAR_STATUS>
<WorkDays type="title" enablehtml="0">
<en><![CDATA[Work Days]]></en>
</WorkDays>
@@ -68,8 +72,13 @@ function submit1 () {
return validateForm(this.form);
}
function submit2 (){
invalidCalendarName = validateCalendarName();
function submit2 () {
if (getField('OLD_NAME').value==''){
invalidCalendarName = validateCalendarName('');
} else {
invalidCalendarName = validateCalendarName(getField('OLD_NAME').value);
}
var startHourMessage= '';
var endHourMessage='';
var invalidNameMessage = '';
@@ -409,12 +418,18 @@ function cancel(){
window.location = 'calendarList';
}
function validateCalendarName(){
function validateCalendarName(name){
var validateMessage = '';
var oldName = '';
if (name!='') {
oldName = '&oldName='+name;
}
var arguments = 'action=calendarName&name='+getField("CALENDAR_NAME").value+oldName;
var oRPC = new leimnud.module.rpc.xmlhttp({
url : 'calendarValidate',
async : false,
args : 'action=calendarName&name='+getField("CALENDAR_NAME").value
args : arguments
});
oRPC.make();
validateMessage=oRPC.xmlhttp.responseText;