- function.js :

-> création d'un fichier functions.js pour extraire la partie LSdebug de
  LSdefault.js.
  -> création d'une méthode getFData() sensiblement la même quand PHP
- LSformElement_text : Création d'une possibilité d'auto-génération en JS de la
  valeur à partir des autres champs du formulaire.
- LSconfirmBox && LSsmoothbox :
  -> ajout d'une méthode positionWhenScrolling() pour le placement de la box
  lors du scroll
- LSconfirmBox : Correction d'un bug IE à la fermeture
This commit is contained in:
Benjamin Renard 2008-07-28 16:30:40 +00:00
parent 6e217e07fa
commit 1228e42fc7
9 changed files with 258 additions and 42 deletions

View file

@ -103,24 +103,6 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
'modify' => 0,
)
),
'cn' => array (
'label' => _('Nom complet'),
'ldap_type' => 'ascii',
'html_type' => 'text',
'required' => 1,
'default_value' => 'titi',
'validation' => 'valid',
'rights' => array(
'self' => 'w',
'user' => 'r',
'admin' => 'w'
),
'view' => 1,
'form' => array (
'modify' => 1,
'create' => 1
)
),
'givenName' => array (
'label' => _('Prenom'),
'ldap_type' => 'ascii',
@ -160,6 +142,27 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
'create' => 1
)
),
'cn' => array (
'label' => _('Nom complet'),
'ldap_type' => 'ascii',
'html_type' => 'text',
'html_options' => array(
'generate_value_format' => '%{givenName} %{sn}',
'autoGenerateOnModify' => false // default : false
),
'required' => 1,
'validation' => 'valid',
'rights' => array(
'self' => 'w',
'user' => 'r',
'admin' => 'w'
),
'view' => 1,
'form' => array (
'modify' => 1,
'create' => 1
)
),
'gidNumber' => array (
'label' => _('Groupe principal'),
'ldap_type' => 'numeric',
@ -254,6 +257,10 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
'label' => _('Adresse e-mail'),
'ldap_type' => 'ascii',
'html_type' => 'text',
'html_options' => array(
'generate_value_format' => '%{uid}@ls.com',
'autoGenerateOnModify' => true
),
'required' => 1,
'check_data' => array (
'email' => array(

View file

@ -110,6 +110,7 @@ define('LS_CSS_DIR', 'templates/css/');
$GLOBALS['defaultJSscipts']=array(
'mootools-core.js',
'mootools-more.js',
'functions.js',
'LSdefault.js'
);

View file

@ -43,7 +43,10 @@ class LSformElement_text extends LSformElement {
$return = $this -> getLabelInfos();
// value
if (!$this -> isFreeze()) {
$return['html'] = "<ul class='LSform'>\n";
$return['html'] = "<ul class='LSform LSformElement_text'>\n";
if ($this -> params['html_options']['generate_value_format']!="") {
$GLOBALS['LSsession'] -> addJSconfigParam($this -> name,$this -> params['html_options']);
}
if (empty($this -> values)) {
$return['html'] .= "<li>".$this -> getEmptyField()."</li>\n";
}
@ -51,19 +54,21 @@ class LSformElement_text extends LSformElement {
foreach ($this -> values as $value) {
$multiple = $this -> getMultipleData();
$id = "LSform_".$this -> name."_".rand();
$return['html'] .= "<li><input type='text' name='".$this -> name."[]' value=\"".$value."\" id='".$id."'>".$multiple."</li>\n";
$return['html'] .= "<li><input type='text' name='".$this -> name."[]' value=\"".$value."\" id='".$id."' class='LSformElement_text' />".$multiple."</li>\n";
}
}
$return['html'] .= "</ul>\n";
$GLOBALS['LSsession'] -> addJSscript('LSformElement_text_field.js');
$GLOBALS['LSsession'] -> addJSscript('LSformElement_text.js');
}
else {
$return['html'] = "<ul class='LSform'>\n";
$return['html'] = "<ul class='LSform LSformElement_text'>\n";
if (empty($this -> values)) {
$return['html'] .= "<li>"._('Aucune valeur definie')."</li>\n";
$return['html'] .= "<li><span class='LSformElement_text'>"._('Aucune valeur definie')."</span><input type='hidden' name='".$this -> name."[]' class='LSformElement_text' value=''/></li>\n";
}
else {
foreach ($this -> values as $value) {
$return['html'] .= "<li>".$value."</li>\n";
$return['html'] .= "<li><span class='LSformElement_text'>".$value."</span><input type='hidden' name='".$this -> name."[]' class='LSformElement_text' value=\"$value\"/></li>\n";
}
}
$return['html'] .= "</ul>\n";
@ -78,7 +83,7 @@ class LSformElement_text extends LSformElement {
*/
function getEmptyField() {
$multiple = $this -> getMultipleData();
return "<input type='text' name='".$this -> name."[]' id='LSform_".$this -> name."_".rand()."'>".$multiple;
return "<input type='text' name='".$this -> name."[]' id='LSform_".$this -> name."_".rand()."' class='LSformElement_text' />".$multiple;
}
}

View file

@ -57,18 +57,34 @@ var LSconfirmBox = new Class({
open: new Fx.Morph(this.box, {duration: 500, transition: Fx.Transitions.Sine.easeOut, onComplete: this.displayContent.bind(this)}),
close: new Fx.Morph(this.box, {duration: 500, transition: Fx.Transitions.Sine.easeOut, onComplete: this.onClose.bind(this)})
};
this._scrolling=0;
},
display: function() {
this.box.setStyle('display','block');
this.position(true);
window.addEvent('resize', this.position.bind(this));
window.addEvent('scroll', this.positionWhenScrolling.bind(this));
},
positionWhenScrolling: function(oldValue) {
if (this._scrolling==0||$type(oldValue)) {
this._scrolling = 1;
var current = window.getScrollTop().toInt();
if (oldValue == current) {
this.position();
this._scrolling=0;
}
else {
this.positionWhenScrolling.delay(200,this,current);
}
}
},
displayContent: function() {
[this.title, this.closeBtn, this.text, this.btnsBox].each(function(el) {
var fx = new Fx.Tween(el,{duration: 200});
fx.start('opacity',0,1);
fx.start('opacity',1);
},this);
},
@ -138,19 +154,13 @@ var LSconfirmBox = new Class({
},
confirm: function() {
if (this._options.onConfirm) {
try {
this._options.onConfirm();
}
catch (e){
console.log('onConfirm : rater');
}
}
this.hide();
if (this._options.onConfirm) {
$try(this._options.onConfirm);
}
},
cancel: function() {
this.hide();
}
});

View file

@ -148,14 +148,7 @@ var LSdefault = new Class({
}
});
window.addEvent(window.ie ? 'load' : 'domready', function() {
varLSdefault = new LSdefault();
});
var LSdebug_active = 0;
function LSdebug() {
if (LSdebug_active != 1) return;
if (typeof console == 'undefined') return;
console.log.apply(this, arguments);
}

View file

@ -0,0 +1,56 @@
var LSformElement_text = new Class({
initialize: function(){
this.fields = new Hash();
this.initialiseLSformElement_text();
},
initialiseLSformElement_text: function(el) {
if (typeof(el) == 'undefined') {
el = document;
}
var getName = /^(.*)\[\]$/
el.getElements('ul.LSformElement_text').each(function(ul) {
var first = ul.getElement('input.LSformElement_text');
if ($type(first)) {
var name = getName.exec(first.name)[1];
this.fields[name] = new LSformElement_text_field(name,first,this);
}
}, this);
this.fields.each(function(el) {
el.start.bind(el)();
},this);
},
getDependsFields: function(format) {
var retval=new Array();
var find = 1;
var getMotif = /%{([A-Za-z0-9]+)}/
var ch = null;
while (find) {
ch = getMotif.exec(format);
if ($type(ch)) {
retval.include(ch[1]);
format=format.replace (
new RegExp('%{'+ch[1]+'}'),
''
);
}
else {
find=0;
}
}
return retval;
},
getInput: function(name) {
return this.fields[name].getInput();
},
getValue: function(name) {
return this.fields[name].getValue();
}
});
window.addEvent(window.ie ? 'load' : 'domready', function() {
varLSformElement_text = new LSformElement_text();
});

View file

@ -0,0 +1,53 @@
var LSformElement_text_field = new Class({
initialize: function(name,input,parent){
this.name = name;
this.parent = parent;
this.input = input;
this.params = varLSdefault.LSjsConfig[this.name];
this._auto=1;
this.input.addEvent('change',this.unauto.bind(this));
},
start: function() {
var force=0;
if ($type(this.params)) {
if (this.params.autoGenerateOnModify) {
force = 1;
}
}
if ((this.input.value=='')||(force)) {
if ($type(this.params)) {
if ($type(this.params['generate_value_format'])) {
this.format = this.params['generate_value_format'];
this.dependsFields = this.parent.getDependsFields(this.format);
this.dependsFields.each(function(el) {
var input = this.parent.getInput.bind(this.parent)(el);
input.addEvent('change',this.refreshValue.bind(this));
},this);
this.fx = new Fx.Tween(this.input,{property: 'background-color',duration:600});
}
}
}
},
getInput: function() {
return this.input;
},
getValue: function() {
return this.input.value;
},
refreshValue: function() {
if (this._auto) {
this.input.value=getFData(this.format,this.parent,'getValue');
this.oldBg=this.input.getStyle('background-color');
this.fx.start('#f16d6d');
(function() {this.fx.start(this.oldBg);}).delay(1000,this);
}
},
unauto: function() {
this._auto=0;
}
});

View file

@ -52,7 +52,9 @@ var LSsmoothbox = new Class({
};
this._open=0;
this._scrolling=0;
window.addEvent('resize', this.position.bind(this));
window.addEvent('scroll', this.positionWhenScrolling.bind(this));
},
position: function(){
@ -69,6 +71,20 @@ var LSsmoothbox = new Class({
}
},
positionWhenScrolling: function(oldValue) {
if (this._scrolling==0||$type(oldValue)) {
this._scrolling = 1;
var current = window.getScrollTop().toInt();
if (oldValue == current) {
this.position();
this._scrolling=0;
}
else {
this.positionWhenScrolling.delay(200,this,current);
}
}
},
overPosition: function() {
var h = window.getScrollHeight()+'px';
var w = window.getScrollWidth()+'px';

View file

@ -0,0 +1,75 @@
var LSdebug_active = 0;
function LSdebug() {
if (LSdebug_active != 1) return;
if (typeof console == 'undefined') return;
console.log.apply(this, arguments);
}
/**
* Construction d'une chaine formatée
*
* Cette fonction retourne la valeur d'une chaine formatée selon le format
* et les données passés en paramètre.
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $format string Format de la chaine
* @param[in] $data mixed Les données pour composés la chaine
* Ce paramètre peut être un tableau de string ou un objet.
* @param[in] $meth string Le nom de la methode de l'objet(s) à appeler pour
* obtenir la valeur de remplacement dans la chaine formatée.
*
* Exemple d'appel :
* getFData('%{test1} je %{test2}',{
* getValue: function(val) {
* var data = {
* test1: 'val_test1',
* test2: 'val_test2'
* };
* return data[val];
* }
* },'getValue');
*
* @retval string La chaine formatée
*/
function getFData(format,data,meth) {
var getMotif = /%{([A-Za-z0-9]+)}/
var find=1;
if(($type(data)=='object') || ($type(data)=='array')) {
if ($type(data[meth])!='function') {
while (find) {
var ch = getMotif.exec(format);
if ($type(ch)) {
format=format.replace (
new RegExp('%{'+ch[1]+'}'),
data[ch[1]]
);
}
else {
find=0;
}
}
}
else {
while (find) {
var ch = getMotif.exec(format);
if ($type(ch)) {
try {
format=format.replace (
new RegExp('%{'+ch[1]+'}'),
data[meth](ch[1])
);
}
catch(e) {
return;
}
}
else {
find=0;
}
}
}
}
return format;
}