LSform : Added data entry form in create mode

This commit is contained in:
Benjamin Renard 2010-11-17 19:00:09 +01:00
parent b1f3f3a16f
commit f2072dcfd2
6 changed files with 182 additions and 14 deletions

View file

@ -106,7 +106,27 @@ $GLOBALS['LSobjects']['LSpeople'] = array (
'sambaNTPassword' 'sambaNTPassword'
) )
) )
) // fin Layout ), // fin Layout
'dataEntryForm' => array (
'simple' => array (
'label' => 'Simple',
'disabledLayout' => true,
'displayedElements' => array (
'uid',
'personalTitle',
'givenName',
'sn',
'cn',
'mail',
'userPassword'
),
'defaultValues' => array (
'description' => 'Create with the simple data entry form',
'loginShell' => 'no',
'gidNumber' => '102001'
)
)
) // fin dataEntryForm
), // fin LSform ), // fin LSform
'LSsearch' => array ( 'LSsearch' => array (

View file

@ -43,6 +43,15 @@ if(LSsession :: startLSsession()) {
else { else {
$form = $object -> getForm('create'); $form = $object -> getForm('create');
} }
if (isset($_REQUEST['LSform_dataEntryForm'])) {
$form -> applyDataEntryForm((string)$_REQUEST['LSform_dataEntryForm']);
$GLOBALS['Smarty'] -> assign('LSform_dataEntryForm',(string)$_REQUEST['LSform_dataEntryForm']);
}
$GLOBALS['Smarty'] -> assign('listAvailableDataEntryForm',array_merge(array(''=>''),LSform :: listAvailableDataEntryForm($LSobject)));
$GLOBALS['Smarty'] -> assign('DataEntryFormLabel',_('Data entry form'));
if ($form->validate()) { if ($form->validate()) {
// Data update for LDAP object // Data update for LDAP object
if ($object -> updateData('create')) { if ($object -> updateData('create')) {

View file

@ -147,3 +147,11 @@ div.LSformWarnBox {
border: 1px solid #f00!important; border: 1px solid #f00!important;
color: #fff!important; color: #fff!important;
} }
/* -- LSform_listAvailableDataEntryForm -- */
p.LSform_listAvailableDataEntryForm {
margin: 2px;
margin-right: 1em;
color: #0072b8;
float: right;
}

View file

@ -45,6 +45,9 @@ class LSform {
var $maxFileSize = NULL; var $maxFileSize = NULL;
var $dataEntryForm = NULL;
var $dataEntryFormConfig = NULL;
var $warnings = array(); var $warnings = array();
/** /**
@ -111,12 +114,16 @@ class LSform {
$GLOBALS['Smarty'] -> assign('LSform_object',$LSform_object); $GLOBALS['Smarty'] -> assign('LSform_object',$LSform_object);
$layout_config=LSconfig :: get("LSobjects.".$LSform_object['type'].".LSform.layout"); $layout_config=LSconfig :: get("LSobjects.".$LSform_object['type'].".LSform.layout");
if (!isset($this -> dataEntryFormConfig['disabledLayout']) || $this -> dataEntryFormConfig['disabledLayout']==false) {
if (is_array($layout_config)) { if (is_array($layout_config)) {
$GLOBALS['Smarty'] -> assign('LSform_layout',$layout_config); $GLOBALS['Smarty'] -> assign('LSform_layout',$layout_config);
$GLOBALS['Smarty'] -> assign('LSform_layout_nofield_label',_('No field.')); $GLOBALS['Smarty'] -> assign('LSform_layout_nofield_label',_('No field.'));
} }
}
$fields = array(); $fields = array();
if (!isset($this -> dataEntryFormConfig['displayedElements']) && !is_array($this -> dataEntryFormConfig['displayedElements'])) {
foreach($this -> elements as $element) { foreach($this -> elements as $element) {
$field = array(); $field = array();
$field = $element -> getDisplay(); $field = $element -> getDisplay();
@ -125,6 +132,31 @@ class LSform {
} }
$fields[$element -> name] = $field; $fields[$element -> name] = $field;
} }
}
else {
foreach($this -> dataEntryFormConfig['displayedElements'] as $elementName) {
if (!isset($this -> elements[$elementName])) {
LSerror :: addErrorCode('LSform_09',$elementName);
continue;
}
$element = $this -> elements[$elementName];
$field = array();
$field = $element -> getDisplay();
if (isset($this -> _elementsErrors[$element -> name])) {
$field['errors']= $this -> _elementsErrors[$element -> name];
}
$fields[$element -> name] = $field;
}
// Add warning for other elements errors
foreach(array_keys($this -> elements) as $name) {
if (isset($this -> _elementsErrors[$name]) && !isset($fields[$name])) {
foreach ($this -> _elementsErrors[$name] as $error) {
$this -> addWarning("$name : $error");
}
}
}
$LSform_header .= "\t<input type='hidden' name='LSform_dataEntryForm' value='".$this -> dataEntryForm."'/>\n";
}
if ($this -> maxFileSize) { if ($this -> maxFileSize) {
$LSform_header.="\t<input type='hidden' name='MAX_FILE_SIZE' value='".$this -> maxFileSize."'/>\n"; $LSform_header.="\t<input type='hidden' name='MAX_FILE_SIZE' value='".$this -> maxFileSize."'/>\n";
@ -379,12 +411,33 @@ class LSform {
* @retval boolean true si les valeurs ont bien été récupérées, false sinon. * @retval boolean true si les valeurs ont bien été récupérées, false sinon.
*/ */
function getPostData() { function getPostData() {
if (is_null($this -> dataEntryForm)) {
foreach($this -> elements as $element_name => $element) { foreach($this -> elements as $element_name => $element) {
if( !($element -> getPostData($this -> _postData)) ) { if( !($element -> getPostData($this -> _postData)) ) {
LSerror :: addErrorCode('LSform_02',$element_name); LSerror :: addErrorCode('LSform_02',$element_name);
return; return;
} }
} }
}
else {
$elementsList = $this -> dataEntryFormConfig['displayedElements'];
if (isset($this -> dataEntryFormConfig['defaultValues']) && is_array($this -> dataEntryFormConfig['defaultValues'])) {
$this -> setPostData($this -> dataEntryFormConfig['defaultValues']);
$elementsList = array_merge($elementsList,array_keys($this -> dataEntryFormConfig['defaultValues']));
}
foreach($elementsList as $elementName) {
if (!isset($this -> elements[$elementName])) {
LSerror :: addErrorCode('LSform_09',$elementName);
continue;
}
$element = $this -> elements[$elementName];
if( !($element -> getPostData($this -> _postData)) ) {
LSerror :: addErrorCode('LSform_02',$element_name);
return;
}
}
}
return true; return true;
} }
@ -555,6 +608,54 @@ class LSform {
$this -> maxFileSize = $size; $this -> maxFileSize = $size;
} }
/**
* Applique un masque de saisie au formulaire
*
* @param[in] $dataEntryForm string Le nom du masque de saisie
*
* @retval boolean True si le masque de saisie a été appliqué, False sinon
**/
function applyDataEntryForm($dataEntryForm) {
$dataEntryForm=(string)$dataEntryForm;
$objType = $this -> ldapObject -> getType();
$config=LSconfig :: get("LSobjects.".$objType.".LSform.dataEntryForm.".$dataEntryForm);
if (is_array($config)) {
if (!is_array($config['displayedElements'])) {
LSerror :: addErrorCode('LSform_08',$dataEntryForm);
}
$this -> dataEntryForm = $dataEntryForm;
$this -> dataEntryFormConfig = $config;
return true;
}
LSerror :: addErrorCode('LSform_07',$dataEntryForm);
return;
}
/**
* Liste les dataEntryForm disponible pour un type d'LSldapObject
*
* @param[in] $type string Le type d'LSldapObject
*
* @retval array Tableau contenant la liste de dataEntryForm disponible pour ce type d'LSldapObject (nom => label)
**/
public static function listAvailableDataEntryForm($type) {
$retval=array();
if (LSsession ::loadLSobject($type)) {
$config=LSconfig :: get("LSobjects.".$type.".LSform.dataEntryForm");
if (is_array($config)) {
foreach($config as $name => $conf) {
if (isset($conf['label'])) {
$retval[$name]=__($conf['label']);
}
else {
$retval[$name]=__($name);
}
}
}
}
return $retval;
}
/** /**
* Ajoute un avertissement au sujet du formulaire * Ajoute un avertissement au sujet du formulaire
* *
@ -614,4 +715,13 @@ _("LSfom : Field type unknow (%{type}).")
LSerror :: defineError('LSform_06', LSerror :: defineError('LSform_06',
_("LSform : Error during the creation of the element '%{element}'.") _("LSform : Error during the creation of the element '%{element}'.")
); );
LSerror :: defineError('LSform_07',
_("LSform : The data entry form %{name} doesn't exist.")
);
LSerror :: defineError('LSform_08',
_("LSform : The data entry form %{name} is not correctly configured.")
);
LSerror :: defineError('LSform_09',
_("LSform : The element %{name}, listed as displayed in data entry form configuration, doesn't exist.")
);
?> ?>

View file

@ -44,6 +44,11 @@ var LSform = new Class({
this.warnBox.display(this.warnTxt); this.warnBox.display(this.warnTxt);
} }
LSdebug(this.params); LSdebug(this.params);
this.listAvailableDataEntryForm=$('LSform_listAvailableDataEntryForm');
if ($type(this.listAvailableDataEntryForm)) {
this.listAvailableDataEntryForm.addEvent('change',this.onListAvailableDataEntryFormChange.bind(this));
}
} }
LSforms = $$('form.LSform'); LSforms = $$('form.LSform');
@ -282,6 +287,14 @@ var LSform = new Class({
this.tmp +="</ul>"; this.tmp +="</ul>";
this.warnBox.display(this.tmp); this.warnBox.display(this.tmp);
} }
},
onListAvailableDataEntryFormChange: function() {
var url=window.location.pathname+"?LSobject="+this.objecttype
if (this.listAvailableDataEntryForm.value!="") {
url+="&LSform_dataEntryForm="+this.listAvailableDataEntryForm.value;
}
document.location=url;
} }
}); });
window.addEvent(window.ie ? 'load' : 'domready', function() { window.addEvent(window.ie ? 'load' : 'domready', function() {

View file

@ -1,5 +1,13 @@
{include file='top.tpl'} {include file='top.tpl'}
{if $pagetitle != ''}<h1 id='LSform_title'>{$pagetitle}</h1>{/if} {if $pagetitle != ''}<h1 id='LSform_title'>{$pagetitle}</h1>{/if}
{if !empty($listAvailableDataEntryForm)}
<p class='LSform_listAvailableDataEntryForm'><label>{$DataEntryFormLabel}
<select id='LSform_listAvailableDataEntryForm'>
{html_options options=$listAvailableDataEntryForm selected=$LSform_dataEntryForm}
</select>
</label>
{/if}
{include file='LSform.tpl'} {include file='LSform.tpl'}
{include file='bottom.tpl'} {include file='bottom.tpl'}