Move custom JS & CSS handling methods from LSsession to LStemplates

The following method are now offer by LStemplate:
 - addJSscript()
 - addLibJSscript()
 - addJSconfigParam()
 - addCssFile()
 - addLibCssFile()
Old methods are always provided by LSsession, but an deprecated error 
message wil be displayed to alert on it.
This commit is contained in:
Benjamin Renard 2020-05-28 16:56:36 +02:00
parent 0b4e6d4104
commit 3fbd9e8073
38 changed files with 324 additions and 164 deletions

View file

@ -212,11 +212,11 @@ grep -Er 'LSsession *:: *addCssFile\(.*\.\.\/' /etc/ldapsaisie/local/</programli
le block <literal>css</literal> : le block <literal>css</literal> :
<programlisting><![CDATA[{block name="css"} <programlisting><![CDATA[{block name="css"}
<link rel="stylesheet" type="text/css" href="{css name='custom.css'}" media="screen" title="Normal" /> <link rel="stylesheet" type="text/css" href="{css name='custom.css'}" media="screen" title="Normal" />
{include file='ls:LSsession_css.tpl'} {include file='ls:css.tpl'}
{/block}]]></programlisting> {/block}]]></programlisting>
</para> </para>
<note><simpara>Ce block contient tous les CSS, y compris ceux gérés par <literal>LSsession :: addCssFile()</literal>. <note><simpara>Ce block contient tous les CSS, y compris ceux gérés par <literal>LSsession :: addCssFile()</literal>.
Pensez à ajouter <literal>{include file='ls:LSsession_css.tpl'}</literal> pour conserver ces derniers.</simpara></note> Pensez à ajouter <literal>{include file='ls:css.tpl'}</literal> pour conserver ces derniers.</simpara></note>
</listitem> </listitem>
<listitem> <listitem>
@ -286,12 +286,12 @@ grep -Er '\.(png|gif|jpg)' /etc/ldapsaisie/local/templates</programlisting>
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<simpara> <simpara>
<literal>{$LSsession_css}</literal> doit être remplacé par <literal>{include file='ls:LSsession_css.tpl'}</literal> <literal>{$LSsession_css}</literal> doit être remplacé par <literal>{include file='ls:css.tpl'}</literal>
</simpara> </simpara>
</listitem> </listitem>
<listitem> <listitem>
<simpara> <simpara>
<literal>{$LSsession_js}</literal> doit être remplacé par <literal>{include file='ls:LSsession_js.tpl'}</literal> <literal>{$LSsession_js}</literal> doit être remplacé par <literal>{include file='ls:js.tpl'}</literal>
</simpara> </simpara>
</listitem> </listitem>
</itemizedlist> </itemizedlist>

View file

@ -259,14 +259,6 @@ $GLOBALS['NB_LSOBJECT_LIST_CHOICES'] = array(30, 60, 100);
define('MAX_SEND_FILE_SIZE',2000000); define('MAX_SEND_FILE_SIZE',2000000);
// Javascript // Default Javascript & CSS to include on all pages
$GLOBALS['defaultJSscipts']=array( $GLOBALS['defaultJSscipts']=array();
'mootools-core.js',
'mootools-more.js',
'functions.js',
'LSdefault.js',
'LSinfosBox.js'
);
// CSS
$GLOBALS['defaultCSSfiles']=array('light-blue.css'); $GLOBALS['defaultCSSfiles']=array('light-blue.css');

View file

@ -157,6 +157,6 @@ function LSaccessRightsMatrixView() {
LStemplate :: assign('LSobjects', $LSobjects); LStemplate :: assign('LSobjects', $LSobjects);
LStemplate :: assign('LSobject', $LSobject); LStemplate :: assign('LSobject', $LSobject);
LSsession :: addCssFile('LSaccessRightsMatrixView.css'); LStemplate :: addCssFile('LSaccessRightsMatrixView.css');
LSsession :: setTemplate('LSaccessRightsMatrixView.tpl'); LSsession :: setTemplate('LSaccessRightsMatrixView.tpl');
} }

View file

@ -28,10 +28,10 @@ class LSconfirmBox {
* @retval void * @retval void
*/ */
public static function loadDependenciesDisplay() { public static function loadDependenciesDisplay() {
LSsession :: addJSscript('LSconfirmBox.js'); LStemplate :: addJSscript('LSconfirmBox.js');
LSsession :: addCssFile('LSconfirmBox.css'); LStemplate :: addCssFile('LSconfirmBox.css');
LSsession :: addJSconfigParam('LSconfirmBox_labels', array( LStemplate :: addJSconfigParam('LSconfirmBox_labels', array(
'title' => _('Confirmation'), 'title' => _('Confirmation'),
'text' => _('You confirm your choice ?'), 'text' => _('You confirm your choice ?'),
'validate' => _('Validate'), 'validate' => _('Validate'),

View file

@ -87,10 +87,10 @@ class LSform {
self :: loadDependenciesDisplayView($this -> $ldapObject); self :: loadDependenciesDisplayView($this -> $ldapObject);
} }
else { else {
LSsession :: addJSscript('LSformElement_field.js'); LStemplate :: addJSscript('LSformElement_field.js');
LSsession :: addJSscript('LSformElement.js'); LStemplate :: addJSscript('LSformElement.js');
LSsession :: addJSscript('LSform.js'); LStemplate :: addJSscript('LSform.js');
LSsession :: addCssFile('LSform.css'); LStemplate :: addCssFile('LSform.css');
} }
LSsession :: addHelpInfos( LSsession :: addHelpInfos(
@ -177,7 +177,7 @@ class LSform {
$JSconfig['warnings']=$this -> warnings; $JSconfig['warnings']=$this -> warnings;
} }
LSsession :: addJSconfigParam('LSform_'.$this -> idForm,$JSconfig); LStemplate :: addJSconfigParam('LSform_'.$this -> idForm,$JSconfig);
LStemplate :: assign('LSform_submittxt',$this -> submit); LStemplate :: assign('LSform_submittxt',$this -> submit);
} }
@ -187,8 +187,8 @@ class LSform {
* @retval void * @retval void
*/ */
public static function loadDependenciesDisplayView($ldapObject=false, $search_view=false) { public static function loadDependenciesDisplayView($ldapObject=false, $search_view=false) {
LSsession :: addCssFile('LSform.css'); LStemplate :: addCssFile('LSform.css');
LSsession :: addJSscript('LSform.js'); LStemplate :: addJSscript('LSform.js');
$customActionLabels = array (); $customActionLabels = array ();
if (is_a($ldapObject,'LSldapObject')) { if (is_a($ldapObject,'LSldapObject')) {
$objectname=($search_view?$ldapObject -> getLabel():$ldapObject -> getDisplayName()); $objectname=($search_view?$ldapObject -> getLabel():$ldapObject -> getDisplayName());
@ -216,7 +216,7 @@ class LSform {
} }
} }
} }
LSsession :: addJSconfigParam('LSview_labels', array_merge(array( LStemplate :: addJSconfigParam('LSview_labels', array_merge(array(
'delete_confirm_text' => _("Do you really want to delete"), 'delete_confirm_text' => _("Do you really want to delete"),
'delete_confirm_title' => _("Caution"), 'delete_confirm_title' => _("Caution"),
'delete_confirm_validate' => _("Delete") 'delete_confirm_validate' => _("Delete")
@ -224,7 +224,7 @@ class LSform {
if (LSsession :: loadLSclass('LSconfirmBox')) { if (LSsession :: loadLSclass('LSconfirmBox')) {
LSconfirmBox :: loadDependenciesDisplay(); LSconfirmBox :: loadDependenciesDisplay();
} }
LSsession :: addJSscript('LSview.js'); LStemplate :: addJSscript('LSview.js');
} }
/** /**

View file

@ -52,7 +52,7 @@ class LSformElement_boolean extends LSformElement {
'clear' => _('Reset the choice.') 'clear' => _('Reset the choice.')
) )
); );
LSsession :: addJSscript('LSformElement_boolean.js'); LStemplate :: addJSscript('LSformElement_boolean.js');
} }
$return['html'] = $this -> fetchTemplate( $return['html'] = $this -> fetchTemplate(
NULL, NULL,

View file

@ -162,18 +162,18 @@ class LSformElement_date extends LSformElement {
'showNowButton' => $this -> getParam('html_options.showNowButton', true, 'bool'), 'showNowButton' => $this -> getParam('html_options.showNowButton', true, 'bool'),
'showTodayButton' => $this -> getParam('html_options.showTodayButton', true, 'bool'), 'showTodayButton' => $this -> getParam('html_options.showTodayButton', true, 'bool'),
); );
LSsession :: addJSconfigParam($this -> name, $params); LStemplate :: addJSconfigParam($this -> name, $params);
$codeLang = str_replace('_','-',preg_replace('/\..*$/','', LSlang :: getLang())); $codeLang = str_replace('_','-',preg_replace('/\..*$/','', LSlang :: getLang()));
LSsession :: addLibJSscript('arian-mootools-datepicker/Picker.js'); LStemplate :: addLibJSscript('arian-mootools-datepicker/Picker.js');
LSsession :: addLibJSscript('arian-mootools-datepicker/Picker.Attach.js'); LStemplate :: addLibJSscript('arian-mootools-datepicker/Picker.Attach.js');
LSsession :: addLibJSscript('arian-mootools-datepicker/Picker.Date.js'); LStemplate :: addLibJSscript('arian-mootools-datepicker/Picker.Date.js');
LSsession :: addLibJSscript('arian-mootools-datepicker/Locale.'.$codeLang.'.DatePicker.js'); LStemplate :: addLibJSscript('arian-mootools-datepicker/Locale.'.$codeLang.'.DatePicker.js');
LSsession :: addLibCssFile('arian-mootools-datepicker/datepicker_'.$params['style'].'/datepicker_'.$params['style'].'.css'); LStemplate :: addLibCssFile('arian-mootools-datepicker/datepicker_'.$params['style'].'/datepicker_'.$params['style'].'.css');
LSsession :: addJSscript('LSformElement_date_field.js'); LStemplate :: addJSscript('LSformElement_date_field.js');
LSsession :: addJSscript('LSformElement_date.js'); LStemplate :: addJSscript('LSformElement_date.js');
} }
$return['html'] = $this -> fetchTemplate(); $return['html'] = $this -> fetchTemplate();
return $return; return $return;

View file

@ -43,7 +43,7 @@ class LSformElement_image extends LSformElement {
* @retval array * @retval array
*/ */
public function getDisplay(){ public function getDisplay(){
LSsession :: addCssFile('LSformElement_image.css'); LStemplate :: addCssFile('LSformElement_image.css');
$return = true; $return = true;
$id=$this -> name.'_'.rand(); $id=$this -> name.'_'.rand();
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
@ -75,7 +75,7 @@ class LSformElement_image extends LSformElement {
if (LSsession :: loadLSclass('LSsmoothbox')) { if (LSsession :: loadLSclass('LSsmoothbox')) {
LSsmoothbox :: loadDependenciesDisplay(); LSsmoothbox :: loadDependenciesDisplay();
} }
LSsession :: addJSscript('LSformElement_image.js'); LStemplate :: addJSscript('LSformElement_image.js');
} }
return $return; return $return;
} }

View file

@ -97,19 +97,19 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
'parseValues' => $parseValues, 'parseValues' => $parseValues,
) )
); );
LSsession :: addCssFile('LSformElement_jsonCompositeAttribute.css'); LStemplate :: addCssFile('LSformElement_jsonCompositeAttribute.css');
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
LSsession :: addJSconfigParam( LStemplate :: addJSconfigParam(
$this -> name, $this -> name,
array ( array (
'components' => $this -> components, 'components' => $this -> components,
) )
); );
LSsession :: addJSscript('LSformElement_jsonCompositeAttribute_field_value_component_text_value.js'); LStemplate :: addJSscript('LSformElement_jsonCompositeAttribute_field_value_component_text_value.js');
LSsession :: addJSscript('LSformElement_jsonCompositeAttribute_field_value_component.js'); LStemplate :: addJSscript('LSformElement_jsonCompositeAttribute_field_value_component.js');
LSsession :: addJSscript('LSformElement_jsonCompositeAttribute_field_value.js'); LStemplate :: addJSscript('LSformElement_jsonCompositeAttribute_field_value.js');
LSsession :: addJSscript('LSformElement_jsonCompositeAttribute_field.js'); LStemplate :: addJSscript('LSformElement_jsonCompositeAttribute_field.js');
LSsession :: addJSscript('LSformElement_jsonCompositeAttribute.js'); LStemplate :: addJSscript('LSformElement_jsonCompositeAttribute.js');
} }
return $return; return $return;

View file

@ -60,7 +60,7 @@ class LSformElement_mail extends LSformElement_text {
LSmail :: loadDependenciesDisplay(); LSmail :: loadDependenciesDisplay();
} }
if (!$this -> isFreeze() && $this -> getParam('html_options.autocomplete')) { if (!$this -> isFreeze() && $this -> getParam('html_options.autocomplete')) {
LSsession :: addJSconfigParam('LSformElement_mail_autocomplete_noResultLabel', _('No result')); LStemplate :: addJSconfigParam('LSformElement_mail_autocomplete_noResultLabel', _('No result'));
} }
return parent :: getDisplay(); return parent :: getDisplay();
} }

View file

@ -82,7 +82,7 @@ class LSformElement_mailQuota extends LSformElement {
} }
} }
LSsession :: addCssFile('LSformElement_mailQuota.css'); LStemplate :: addCssFile('LSformElement_mailQuota.css');
$return['html'] = $this -> fetchTemplate( $return['html'] = $this -> fetchTemplate(
NULL, NULL,

View file

@ -122,7 +122,7 @@ class LSformElement_password extends LSformElement {
* @retval array * @retval array
*/ */
public function getDisplay(){ public function getDisplay(){
LSsession :: addCssFile('LSformElement_password.css'); LStemplate :: addCssFile('LSformElement_password.css');
$return = $this -> getLabelInfos(); $return = $this -> getLabelInfos();
$pwd = ""; $pwd = "";
if ($this -> getParam('html_options.clearView') or $this -> getParam('html_options.clearEdit')) { if ($this -> getParam('html_options.clearView') or $this -> getParam('html_options.clearEdit')) {
@ -160,10 +160,10 @@ class LSformElement_password extends LSformElement {
$params['mail'] = $this -> getParam('html_options.mail'); $params['mail'] = $this -> getParam('html_options.mail');
$params['mail']['mail_attr'] = $this -> getMailAttrs(); $params['mail']['mail_attr'] = $this -> getMailAttrs();
} }
LSsession :: addJSconfigParam($this -> name, $params); LStemplate :: addJSconfigParam($this -> name, $params);
LSsession :: addJSscript('LSformElement_password_field.js'); LStemplate :: addJSscript('LSformElement_password_field.js');
LSsession :: addJSscript('LSformElement_password.js'); LStemplate :: addJSscript('LSformElement_password.js');
} }
$return['html'] = $this -> fetchTemplate ( $return['html'] = $this -> fetchTemplate (
NULL, NULL,

View file

@ -63,7 +63,7 @@ class LSformElement_postaladdress extends LSformElement_textarea {
else { else {
$this -> attr_html -> attribute -> ldapObject -> registerOtherValue('pattern', LSformElement_postaladdress__generate_pattern($this)); $this -> attr_html -> attribute -> ldapObject -> registerOtherValue('pattern', LSformElement_postaladdress__generate_pattern($this));
} }
LSsession :: addJSconfigParam('LSformElement_postaladdress_'.$this -> name, array ( LStemplate :: addJSconfigParam('LSformElement_postaladdress_'.$this -> name, array (
'map_url' => $this -> attr_html -> attribute -> ldapObject -> getFData($map_url_format) 'map_url' => $this -> attr_html -> attribute -> ldapObject -> getFData($map_url_format)
) )
); );
@ -73,7 +73,7 @@ class LSformElement_postaladdress extends LSformElement_textarea {
'viewOnMap' => _('View on map') 'viewOnMap' => _('View on map')
) )
); );
LSsession :: addJSscript('LSformElement_postaladdress.js'); LStemplate :: addJSscript('LSformElement_postaladdress.js');
} }
} }
return $return; return $return;

View file

@ -41,7 +41,7 @@ class LSformElement_pre extends LSformElement_textarea {
*/ */
public function getDisplay(){ public function getDisplay(){
$return = parent :: getDisplay(); $return = parent :: getDisplay();
LSsession :: addCssFile('LSformElement_pre.css'); LStemplate :: addCssFile('LSformElement_pre.css');
return $return; return $return;
} }

View file

@ -82,7 +82,7 @@ class LSformElement_quota extends LSformElement {
} }
} }
LSsession :: addCssFile('LSformElement_quota.css'); LStemplate :: addCssFile('LSformElement_quota.css');
$return['html'] = $this -> fetchTemplate( $return['html'] = $this -> fetchTemplate(
NULL, NULL,

View file

@ -52,7 +52,7 @@ class LSformElement_select extends LSformElement {
'clear' => _("Reset selection.") 'clear' => _("Reset selection.")
) )
); );
LSsession :: addJSscript('LSformElement_select.js'); LStemplate :: addJSscript('LSformElement_select.js');
} }
$params['possible_values'] = $this -> params['text_possible_values']; $params['possible_values'] = $this -> params['text_possible_values'];
$params['unrecognized_value_label_format'] = _("%{value} (unrecognized value)"); $params['unrecognized_value_label_format'] = _("%{value} (unrecognized value)");

View file

@ -45,7 +45,7 @@ class LSformElement_select_box extends LSformElement_select {
*/ */
public function getDisplay(){ public function getDisplay(){
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
LSsession :: addCssFile('LSformElement_select_box.css'); LStemplate :: addCssFile('LSformElement_select_box.css');
} }
$this -> fetchVariables['translate_labels'] = $this -> getParam('translate_labels', true); $this -> fetchVariables['translate_labels'] = $this -> getParam('translate_labels', true);
return parent :: getDisplay(); return parent :: getDisplay();

View file

@ -54,14 +54,14 @@ class LSformElement_select_object extends LSformElement {
* @retval array * @retval array
*/ */
public function getDisplay($refresh=NULL){ public function getDisplay($refresh=NULL){
LSsession :: addCssFile('LSformElement_select_object.css'); LStemplate :: addCssFile('LSformElement_select_object.css');
if ($refresh) { if ($refresh) {
$this -> values = $this -> getValuesFromLSselect(); $this -> values = $this -> getValuesFromLSselect();
} }
$return = $this -> getLabelInfos(); $return = $this -> getLabelInfos();
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
LSsession :: addJSconfigParam( LStemplate :: addJSconfigParam(
$this -> name, $this -> name,
array( array(
'LSselect_id' => $this -> attr_html -> getLSselectId(), 'LSselect_id' => $this -> attr_html -> getLSselectId(),
@ -86,8 +86,8 @@ class LSformElement_select_object extends LSformElement {
) )
); );
LSsession :: addJSscript('LSformElement_select_object_field.js'); LStemplate :: addJSscript('LSformElement_select_object_field.js');
LSsession :: addJSscript('LSformElement_select_object.js'); LStemplate :: addJSscript('LSformElement_select_object.js');
if (LSsession :: loadLSclass('LSselect') && $this -> initLSselect()) { if (LSsession :: loadLSclass('LSselect') && $this -> initLSselect()) {
LSselect :: loadDependenciesDisplay(); LSselect :: loadDependenciesDisplay();
} }

View file

@ -43,14 +43,14 @@ class LSformElement_ssh_key extends LSformElement {
* @retval array * @retval array
*/ */
public function getDisplay(){ public function getDisplay(){
LSsession :: addCssFile('LSformElement_ssh_key.css'); LStemplate :: addCssFile('LSformElement_ssh_key.css');
$return = $this -> getLabelInfos(); $return = $this -> getLabelInfos();
$params = array(); $params = array();
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
$params['values_txt'] = $this -> values; $params['values_txt'] = $this -> values;
} }
else { else {
LSsession :: addJSscript('LSformElement_ssh_key.js'); LStemplate :: addJSscript('LSformElement_ssh_key.js');
LSsession :: addHelpInfos ( LSsession :: addHelpInfos (
'LSformElement_ssh_key', 'LSformElement_ssh_key',
array( array(

View file

@ -98,9 +98,9 @@ class LSformElement_supannCompositeAttribute extends LSformElement {
'components' => $this -> components 'components' => $this -> components
) )
); );
LSsession :: addCssFile('LSformElement_supannCompositeAttribute.css'); LStemplate :: addCssFile('LSformElement_supannCompositeAttribute.css');
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
LSsession :: addJSconfigParam( LStemplate :: addJSconfigParam(
$this -> name, $this -> name,
array( array(
'searchBtn' => _('Modify'), 'searchBtn' => _('Modify'),
@ -109,10 +109,10 @@ class LSformElement_supannCompositeAttribute extends LSformElement {
'components' => $this->components 'components' => $this->components
) )
); );
LSsession :: addJSscript('LSformElement_supannCompositeAttribute_field_value_component.js'); LStemplate :: addJSscript('LSformElement_supannCompositeAttribute_field_value_component.js');
LSsession :: addJSscript('LSformElement_supannCompositeAttribute_field_value.js'); LStemplate :: addJSscript('LSformElement_supannCompositeAttribute_field_value.js');
LSsession :: addJSscript('LSformElement_supannCompositeAttribute_field.js'); LStemplate :: addJSscript('LSformElement_supannCompositeAttribute_field.js');
LSsession :: addJSscript('LSformElement_supannCompositeAttribute.js'); LStemplate :: addJSscript('LSformElement_supannCompositeAttribute.js');
} }
return $return; return $return;
} }

View file

@ -54,9 +54,9 @@ class LSformElement_supannLabeledValue extends LSformElement {
$parseValues[]=$this -> parseValue($val); $parseValues[]=$this -> parseValue($val);
} }
$return['html'] = $this -> fetchTemplate(NULL,array('parseValues' => $parseValues)); $return['html'] = $this -> fetchTemplate(NULL,array('parseValues' => $parseValues));
LSsession :: addCssFile('LSformElement_supannLabeledValue.css'); LStemplate :: addCssFile('LSformElement_supannLabeledValue.css');
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
LSsession :: addJSconfigParam( LStemplate :: addJSconfigParam(
$this -> name, $this -> name,
array( array(
'searchBtn' => _('Modify'), 'searchBtn' => _('Modify'),
@ -65,9 +65,9 @@ class LSformElement_supannLabeledValue extends LSformElement {
'components' => $this->components 'components' => $this->components
) )
); );
LSsession :: addJSscript('LSformElement_supannLabeledValue_field_value.js'); LStemplate :: addJSscript('LSformElement_supannLabeledValue_field_value.js');
LSsession :: addJSscript('LSformElement_supannLabeledValue_field.js'); LStemplate :: addJSscript('LSformElement_supannLabeledValue_field.js');
LSsession :: addJSscript('LSformElement_supannLabeledValue.js'); LStemplate :: addJSscript('LSformElement_supannLabeledValue.js');
} }
return $return; return $return;
} }

View file

@ -49,7 +49,7 @@ class LSformElement_text extends LSformElement {
// value // value
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
if ($this -> getParam('html_options')) { if ($this -> getParam('html_options')) {
LSsession :: addJSconfigParam($this -> name, $this -> getParam('html_options')); LStemplate :: addJSconfigParam($this -> name, $this -> getParam('html_options'));
} }
LSsession :: addHelpInfos( LSsession :: addHelpInfos(
'LSformElement_text', 'LSformElement_text',
@ -57,14 +57,14 @@ class LSformElement_text extends LSformElement {
'generate' => _('Generate the value') 'generate' => _('Generate the value')
) )
); );
LSsession :: addJSscript('LSformElement_text_field.js'); LStemplate :: addJSscript('LSformElement_text_field.js');
LSsession :: addJSscript('LSformElement_text.js'); LStemplate :: addJSscript('LSformElement_text.js');
} }
foreach ($this -> JSscripts as $js) { foreach ($this -> JSscripts as $js) {
LSsession :: addJSscript($js); LStemplate :: addJSscript($js);
} }
foreach ($this -> CSSfiles as $css) { foreach ($this -> CSSfiles as $css) {
LSsession :: addCssFile($css); LStemplate :: addCssFile($css);
} }
$return['html'] = $this -> fetchTemplate(); $return['html'] = $this -> fetchTemplate();
return $return; return $return;

View file

@ -51,9 +51,9 @@ class LSformElement_textarea extends LSformElement {
'clear' => _('Clear') 'clear' => _('Clear')
) )
); );
LSsession :: addJSscript('LSformElement_textarea.js'); LStemplate :: addJSscript('LSformElement_textarea.js');
} }
LSsession :: addCssFile('LSformElement_textarea.css'); LStemplate :: addCssFile('LSformElement_textarea.css');
$return['html'] = $this -> fetchTemplate( $return['html'] = $this -> fetchTemplate(
NULL, NULL,
array ( array (

View file

@ -111,7 +111,7 @@ class LSformElement_valueWithUnit extends LSformElement {
} }
} }
LSsession :: addCssFile('LSformElement_valueWithUnit.css'); LStemplate :: addCssFile('LSformElement_valueWithUnit.css');
$return['html']=$this -> fetchTemplate( $return['html']=$this -> fetchTemplate(
NULL, NULL,

View file

@ -43,17 +43,17 @@ class LSformElement_wysiwyg extends LSformElement {
public function getDisplay(){ public function getDisplay(){
$return = $this -> getLabelInfos(); $return = $this -> getLabelInfos();
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
LSsession :: addLibJSscript('tinymce/js/tinymce/tinymce.min.js'); LStemplate :: addLibJSscript('tinymce/js/tinymce/tinymce.min.js');
LSsession :: addJSconfigParam( LStemplate :: addJSconfigParam(
$this -> name, $this -> name,
array( array(
'extra_options' => $this -> getParam('html_options.extra_options', array()), 'extra_options' => $this -> getParam('html_options.extra_options', array()),
) )
); );
} }
LSsession :: addJSscript('LSformElement_wysiwyg_field.js'); LStemplate :: addJSscript('LSformElement_wysiwyg_field.js');
LSsession :: addJSscript('LSformElement_wysiwyg.js'); LStemplate :: addJSscript('LSformElement_wysiwyg.js');
LSsession :: addCssFile('LSformElement_wysiwyg.css'); LStemplate :: addCssFile('LSformElement_wysiwyg.css');
$return['html'] = $this -> fetchTemplate(); $return['html'] = $this -> fetchTemplate();
return $return; return $return;
} }

View file

@ -32,8 +32,8 @@ class LSmail {
LSsmoothbox :: loadDependenciesDisplay(); LSsmoothbox :: loadDependenciesDisplay();
} }
LSsession :: addJSscript('LSmail.js'); LStemplate :: addJSscript('LSmail.js');
LSsession :: addCssFile('LSmail.css'); LStemplate :: addCssFile('LSmail.css');
} }
public static function ajax_display(&$data) { public static function ajax_display(&$data) {

View file

@ -595,10 +595,10 @@ class LSrelation extends LSlog_staticLoggerClass {
if (LSsession :: loadLSclass('LSselect')) { if (LSsession :: loadLSclass('LSselect')) {
LSselect :: loadDependenciesDisplay(); LSselect :: loadDependenciesDisplay();
} }
LSsession :: addJSscript('LSrelation.js'); LStemplate :: addJSscript('LSrelation.js');
LSsession :: addCssFile('LSrelation.css'); LStemplate :: addCssFile('LSrelation.css');
LSsession :: addJSconfigParam('LSrelation_labels', array( LStemplate :: addJSconfigParam('LSrelation_labels', array(
'close_confirm_text' => _('Do you really want to delete'), 'close_confirm_text' => _('Do you really want to delete'),
'close_confirm_title' => _('Warning'), 'close_confirm_title' => _('Warning'),
'close_confirm_validate' => _('Delete') 'close_confirm_validate' => _('Delete')
@ -689,7 +689,7 @@ class LSrelation extends LSlog_staticLoggerClass {
self :: loadDependenciesDisplay(); self :: loadDependenciesDisplay();
LStemplate :: assign('LSrelations',$LSrelations); LStemplate :: assign('LSrelations',$LSrelations);
LSsession :: addJSconfigParam('LSrelations',$LSrelations_JSparams); LStemplate :: addJSconfigParam('LSrelations',$LSrelations_JSparams);
} }
/* /*

View file

@ -33,8 +33,8 @@ class LSselect extends LSlog_staticLoggerClass {
if (LSsession :: loadLSclass('LSsmoothbox')) { if (LSsession :: loadLSclass('LSsmoothbox')) {
LSsmoothbox :: loadDependenciesDisplay(); LSsmoothbox :: loadDependenciesDisplay();
} }
LSsession :: addJSscript('LSselect.js'); LStemplate :: addJSscript('LSselect.js');
LSsession :: addCssFile('LSselect.css'); LStemplate :: addCssFile('LSselect.css');
} }
/** /**

View file

@ -1356,7 +1356,7 @@ class LSsession {
LStemplate :: assign('ldapservers', $ldapservers); LStemplate :: assign('ldapservers', $ldapservers);
LStemplate :: assign('ldapServerId', (self :: $ldapServerId?self :: $ldapServerId:0)); LStemplate :: assign('ldapServerId', (self :: $ldapServerId?self :: $ldapServerId:0));
self :: setTemplate('login.tpl'); self :: setTemplate('login.tpl');
self :: addJSscript('LSsession_login.js'); LStemplate :: addJSscript('LSsession_login.js');
} }
/** /**
@ -1403,7 +1403,7 @@ class LSsession {
LStemplate :: assign('recoverpassword_msg', $recoverpassword_msg); LStemplate :: assign('recoverpassword_msg', $recoverpassword_msg);
self :: setTemplate('recoverpassword.tpl'); self :: setTemplate('recoverpassword.tpl');
self :: addJSscript('LSsession_recoverPassword.js'); LStemplate :: addJSscript('LSsession_recoverPassword.js');
} }
/** /**
@ -1425,28 +1425,44 @@ class LSsession {
* *
* @param[in] $file string The JS filename * @param[in] $file string The JS filename
* @param[in] $path string|null The sub-directory path that contain this file. * @param[in] $path string|null The sub-directory path that contain this file.
* Keep for retro-compatibility : you could just * @deprecated
* prefix the file name. * @see LStemplate :: addJSscript()
* *
* @retval void * @retval void
*/ */
public static function addJSscript($file, $path=NULL) { public static function addJSscript($file, $path=NULL) {
if ($path) if ($path)
$file = $path.$file; $file = $path.$file;
if (!in_array($file, self :: $JSscripts)) LStemplate :: addJSscript($file);
self :: $JSscripts[] = $file; LSerror :: addErrorCode(
'LSsession_27',
array(
'old' => 'LStemplate :: addJSscript()',
'new' => 'LStemplate :: addJSscript()',
'context' => LSlog :: get_debug_backtrace_context(),
)
);
} }
/** /**
* Add a library JS file to load on page * Add a library JS file to load on page
* *
* @param[in] $file string The JS filename * @param[in] $file string The JS filename
* @deprecated
* @see LStemplate :: addLibJSscript()
* *
* @retval void * @retval void
*/ */
public static function addLibJSscript($file) { public static function addLibJSscript($file) {
if (!in_array($file, self :: $LibsJSscripts)) LStemplate :: addLibJSscript($file);
self :: $LibsJSscripts[] = $file; LSerror :: addErrorCode(
'LSsession_27',
array(
'old' => 'LStemplate :: addLibJSscript()',
'new' => 'LStemplate :: addLibJSscript()',
'context' => LSlog :: get_debug_backtrace_context(),
)
);
} }
/** /**
@ -1454,11 +1470,22 @@ class LSsession {
* *
* @param[in] $name string Nom de la variable de configuration * @param[in] $name string Nom de la variable de configuration
* @param[in] $val mixed Valeur de la variable de configuration * @param[in] $val mixed Valeur de la variable de configuration
* @deprecated
* @see LStemplate :: addJSconfigParam()
* *
* @retval void * @retval void
*/ */
public static function addJSconfigParam($name, $val) { public static function addJSconfigParam($name, $val) {
self :: $_JSconfigParams[$name]=$val; LStemplate :: addJSconfigParam($name, $val);
LSerror :: addErrorCode(
'LSsession_27',
array(
'old' => 'LStemplate :: addJSconfigParam()',
'new' => 'LStemplate :: addJSconfigParam()',
'context' => LSlog :: get_debug_backtrace_context(),
),
false
);
} }
/** /**
@ -1466,28 +1493,44 @@ class LSsession {
* *
* @param[in] $file string The CSS filename * @param[in] $file string The CSS filename
* @param[in] $path string|null The sub-directory path that contain this file. * @param[in] $path string|null The sub-directory path that contain this file.
* Keep for retro-compatibility : you could just * @deprecated
* prefix the file name. * @see LStemplate :: addCssFile()
* *
* @retval void * @retval void
*/ */
public static function addCssFile($file, $path=NULL) { public static function addCssFile($file, $path=NULL) {
if ($path) if ($path)
$file = $path.$file; $file = $path.$file;
if (!in_array($file, self :: $CssFiles)) LStemplate :: addCssFile($file);
self :: $CssFiles[] = $file; LSerror :: addErrorCode(
'LSsession_27',
array(
'old' => 'LStemplate :: addCssFile()',
'new' => 'LStemplate :: addCssFile()',
'context' => LSlog :: get_debug_backtrace_context(),
)
);
} }
/** /**
* Add a library CSS file to load on page * Add a library CSS file to load on page
* *
* @param[in] $file string The CSS filename * @param[in] $file string The CSS filename
* @deprecated
* @see LStemplate :: addLibCssFile()
* *
* @retval void * @retval void
*/ */
public static function addLibCssFile($file) { public static function addLibCssFile($file) {
if (!in_array($file, self :: $LibsCssFiles)) LStemplate :: addLibCssFile($file);
self :: $LibsCssFiles[] = $file; LSerror :: addErrorCode(
'LSsession_27',
array(
'old' => 'LStemplate :: addLibCssFile()',
'new' => 'LStemplate :: addLibCssFile()',
'context' => LSlog :: get_debug_backtrace_context(),
)
);
} }
/** /**
@ -1508,34 +1551,9 @@ class LSsession {
|| ||
(self :: $ldapServer['keepLSsessionActive']) (self :: $ldapServer['keepLSsessionActive'])
) { ) {
self :: addJSconfigParam('keepLSsessionActive',ini_get('session.gc_maxlifetime')); LStemplate :: addJSconfigParam('keepLSsessionActive',ini_get('session.gc_maxlifetime'));
} }
LStemplate :: assign('LSjsConfig',base64_encode(json_encode(self :: $_JSconfigParams)));
// JS files
$JSscripts = array();
if (isset($GLOBALS['defaultJSscipts']) && is_array($GLOBALS['defaultJSscipts']))
foreach ($GLOBALS['defaultJSscipts'] as $script)
if (!in_array($script, $JSscripts))
$JSscripts[] = $script;
foreach (self :: $JSscripts as $script)
if (!in_array($script, $JSscripts))
$JSscripts[] = $script;
LStemplate :: assign('JSscripts', $JSscripts);
LStemplate :: assign('LibsJSscripts', self :: $LibsJSscripts);
LStemplate :: assign('LSdebug', boolval(LSdebug));
// CSS files
self :: addCssFile("LSdefault.css");
if (isset($GLOBALS['defaultCSSfiles']) && is_array($GLOBALS['defaultCSSfiles']))
foreach ($GLOBALS['defaultCSSfiles'] as $file)
if (!in_array($script, self :: $CssFiles))
self :: addCssFile($file);
LStemplate :: assign('CssFiles', self :: $CssFiles);
LStemplate :: assign('LibsCssFiles', self :: $LibsCssFiles);
// Access // Access
LStemplate :: assign('LSaccess', self :: getLSaccess()); LStemplate :: assign('LSaccess', self :: getLSaccess());
LStemplate :: assign('LSaddonsViewsAccess', self :: $LSaddonsViewsAccess); LStemplate :: assign('LSaddonsViewsAccess', self :: $LSaddonsViewsAccess);
@ -2574,7 +2592,14 @@ class LSsession {
* @retval void * @retval void
*/ */
public static function redirect($url, $exit=true) { public static function redirect($url, $exit=true) {
LSerror :: addErrorCode('LSsession_27'); LSerror :: addErrorCode(
'LSsession_27',
array(
'old' => 'LSsession :: redirect()',
'new' => 'LSurl :: redirect()',
'context' => LSlog :: get_debug_backtrace_context(),
)
);
LSurl :: redirect($url); LSurl :: redirect($url);
} }
@ -2714,7 +2739,7 @@ class LSsession {
_("LSsession : You have been redirect from an old-style URL %{url}. Please upgrade this link.") _("LSsession : You have been redirect from an old-style URL %{url}. Please upgrade this link.")
); );
LSerror :: defineError('LSsession_27', LSerror :: defineError('LSsession_27',
_("LSsession : You still seen use LSsession :: redirect() in your custom code. Please upgrade it and use LSurl :: redirect().") _("LSsession : You always seem to use %{old} in your custom code: Please upgrade it and use %{new}.<pre>\nContext:\n%{context}</pre>")
); );
} }

View file

@ -31,10 +31,10 @@ class LSsmoothbox {
if (LSsession :: loadLSclass('LSconfirmBox')) { if (LSsession :: loadLSclass('LSconfirmBox')) {
LSconfirmBox :: loadDependenciesDisplay(); LSconfirmBox :: loadDependenciesDisplay();
} }
LSsession :: addJSscript('LSsmoothbox.js'); LStemplate :: addJSscript('LSsmoothbox.js');
LSsession :: addCssFile('LSsmoothbox.css'); LStemplate :: addCssFile('LSsmoothbox.css');
LSsession :: addJSconfigParam('LSsmoothbox_labels', array( LStemplate :: addJSconfigParam('LSsmoothbox_labels', array(
'close_confirm_text' => _('Are you sure to want to close this window and lose all changes ?'), 'close_confirm_text' => _('Are you sure to want to close this window and lose all changes ?'),
'validate' => _('Validate') 'validate' => _('Validate')
)); ));

View file

@ -31,6 +31,21 @@ LSsession :: loadLSclass('LSlog_staticLoggerClass');
*/ */
class LStemplate extends LSlog_staticLoggerClass { class LStemplate extends LSlog_staticLoggerClass {
// Javascript files to load on page
private static $JSscripts = array();
// Libs JS files to load on page
private static $LibsJSscripts = array();
// Javascript configuration parameter to set on page
private static $JSconfigParams = array();
// CSS files to load on page
private static $CssFiles = array();
// Libs CSS files to load on page
private static $LibsCssFiles = array();
/** /**
* LStemplate configuration * LStemplate configuration
* *
@ -350,6 +365,48 @@ class LStemplate extends LSlog_staticLoggerClass {
return self :: $_smarty -> assign($name,$value); return self :: $_smarty -> assign($name,$value);
} }
/**
* Assign common template variables
*
* @retval void
**/
public static function assignCommonVars() {
// JS config
LStemplate :: assign('LSjsConfig', base64_encode(json_encode(self :: $JSconfigParams)));
// JS files
$defaultJSscripts = array(
'mootools-core.js',
'mootools-more.js',
'functions.js',
'LSdefault.js',
'LSinfosBox.js',
);
if (isset($GLOBALS['defaultJSscripts']) && is_array($GLOBALS['defaultJSscripts']))
foreach ($GLOBALS['defaultJSscripts'] as $file)
if (!in_array($file, $defaultJSscripts))
$defaultJSscripts[] = $file;
LStemplate :: assign('defaultJSscripts', $defaultJSscripts);
$JSscripts = array();
foreach (self :: $JSscripts as $script)
if (!in_array($script, $JSscripts) && !in_array($script, $defaultJSscripts))
$JSscripts[] = $script;
LStemplate :: assign('JSscripts', $JSscripts);
LStemplate :: assign('LibsJSscripts', self :: $LibsJSscripts);
LStemplate :: assign('LSdebug', boolval(LSdebug));
// CSS files
$defaultCssFiles = array("LSdefault.css");
if (isset($GLOBALS['defaultCSSfiles']) && is_array($GLOBALS['defaultCSSfiles']))
foreach ($GLOBALS['defaultCSSfiles'] as $file)
if (!in_array($file, $defaultCssFiles))
$defaultCssFiles[] = $file;
LStemplate :: assign('defaultCssFiles', $defaultCssFiles);
LStemplate :: assign('CssFiles', self :: $CssFiles);
LStemplate :: assign('LibsCssFiles', self :: $LibsCssFiles);
}
/** /**
* Display a template * Display a template
* *
@ -362,6 +419,7 @@ class LStemplate extends LSlog_staticLoggerClass {
self :: fireEvent('displaying'); self :: fireEvent('displaying');
try { try {
self :: assignCommonVars();
self :: $_smarty -> display("ls:$template"); self :: $_smarty -> display("ls:$template");
} }
catch (Exception $e) { catch (Exception $e) {
@ -464,6 +522,77 @@ class LStemplate extends LSlog_staticLoggerClass {
return $return; return $return;
} }
/*
* Javascript & CSS files helpers methods
*/
/**
* Add a JS script to load on page
*
* @param[in] $file string The JS filename
*
* Note: about old $path of the LStemplate :: addJSscript() method, corresponding to
* the sub-directory path that contain the file, you could just prefix the file name.
*
* @retval void
*/
public static function addJSscript($file) {
if (!in_array($file, self :: $JSscripts))
self :: $JSscripts[] = $file;
}
/**
* Add a library JS file to load on page
*
* @param[in] $file string The JS filename
*
* @retval void
*/
public static function addLibJSscript($file) {
if (!in_array($file, self :: $LibsJSscripts))
self :: $LibsJSscripts[] = $file;
}
/**
* Add Javascript configuration parameter
*
* @param[in] $name string Name of the configuration parameter
* @param[in] $val mixed Value of the configuration parameter
*
* @retval void
*/
public static function addJSconfigParam($name,$val) {
self :: $JSconfigParams[$name]=$val;
}
/**
* Add a CSS file to load on page
*
* @param[in] $file string The CSS filename
*
* Note: about old $path of the LStemplate :: addCssFile() method, corresponding to
* the sub-directory path that contain the file, you could just prefix the file name.
*
* @retval void
*/
public static function addCssFile($file) {
if (!in_array($file, self :: $CssFiles))
self :: $CssFiles[] = $file;
}
/**
* Add a library CSS file to load on page
*
* @param[in] $file string The CSS filename
*
* @retval void
*/
public static function addLibCssFile($file) {
if (!in_array($file, self :: $LibsCssFiles))
self :: $LibsCssFiles[] = $file;
}
} }
function LStemplate_smarty_getFData($params) { function LStemplate_smarty_getFData($params) {

View file

@ -742,8 +742,8 @@ function handle_LSobject_import($request) {
// Set & display template // Set & display template
LSsession :: setTemplate('import.tpl'); LSsession :: setTemplate('import.tpl');
LSsession :: addCssFile('LSform.css'); LStemplate :: addCssFile('LSform.css');
LSsession :: addCssFile('LSimport.css'); LStemplate :: addCssFile('LSimport.css');
LSsession :: displayTemplate(); LSsession :: displayTemplate();
} }
LSurl :: add_handler('#^object/(?P<LSobject>[^/]+)/import/?$#', 'handle_LSobject_import'); LSurl :: add_handler('#^object/(?P<LSobject>[^/]+)/import/?$#', 'handle_LSobject_import');

View file

@ -1,13 +0,0 @@
{if isset($CssFiles) && is_array($CssFiles)}
<!-- Additional CSS files -->
{foreach $CssFiles as $file}
<link rel="stylesheet" type="text/css" href="{css name=$file}" title="Normal" />
{/foreach}
{/if}
{if isset($LibsCssFiles) && is_array($LibsCssFiles)}
<!-- Additional libraries CSS files -->
{foreach $LibsCssFiles as $file}
<link rel="stylesheet" type="text/css" href="libs/{$file}" title="Normal" />
{/foreach}
{/if}

View file

@ -9,7 +9,7 @@
{block name="css"} {block name="css"}
<link rel="stylesheet" type="text/css" href="{css name='base.css'}" title="Normal" /> <link rel="stylesheet" type="text/css" href="{css name='base.css'}" title="Normal" />
<link rel="stylesheet" type="text/css" href="{css name='base_print.css'}" media='print' title="Normal" /> <link rel="stylesheet" type="text/css" href="{css name='base_print.css'}" media='print' title="Normal" />
{include file='ls:LSsession_css.tpl'} {include file='ls:css.tpl'}
{/block} {/block}
{block name="head"}{/block} {block name="head"}{/block}
</head> </head>
@ -19,7 +19,7 @@
{block name="body"}{/block} {block name="body"}{/block}
{include file='ls:LSsession_js.tpl'} {include file='ls:js.tpl'}
{block name="js"}{/block} {block name="js"}{/block}
</body> </body>
</html> </html>

View file

@ -0,0 +1,20 @@
{if isset($LibsCssFiles) && is_array($LibsCssFiles) && !empty($LibsCssFiles)}
<!-- Additional libraries CSS files -->
{foreach $LibsCssFiles as $file}
<link rel="stylesheet" type="text/css" href="libs/{$file}" title="Normal" />
{/foreach}
{/if}
{if isset($CssFiles) && is_array($CssFiles) && !empty($CssFiles)}
<!-- Additional CSS files -->
{foreach $CssFiles as $file}
<link rel="stylesheet" type="text/css" href="{css name=$file}" title="Normal" />
{/foreach}
{/if}
{if isset($defaultCssFiles) && is_array($defaultCssFiles) && !empty($defaultCssFiles)}
<!-- Default CSS files -->
{foreach $defaultCssFiles as $file}
<link rel="stylesheet" type="text/css" href="{css name=$file}" title="Normal" />
{/foreach}
{/if}

View file

@ -1,4 +1,11 @@
{if isset($JSscripts) && is_array($JSscripts)} {if isset($defaultJSscripts) && is_array($defaultJSscripts) && !empty($defaultJSscripts)}
<!-- JS files -->
{foreach $defaultJSscripts as $file}
<script src="js/{$file}" type="text/javascript"></script>
{/foreach}
{/if}
{if isset($JSscripts) && is_array($JSscripts) && !empty($JSscripts)}
<!-- JS files --> <!-- JS files -->
{foreach $JSscripts as $file} {foreach $JSscripts as $file}
<script src="js/{$file}" type="text/javascript"></script> <script src="js/{$file}" type="text/javascript"></script>
@ -8,7 +15,7 @@
<!-- Set LSdebug status --> <!-- Set LSdebug status -->
<script type='text/javascript'>LSdebug_active = {if $LSdebug}1{else}0{/if};</script> <script type='text/javascript'>LSdebug_active = {if $LSdebug}1{else}0{/if};</script>
{if isset($LibsJSscripts) && is_array($LibsJSscripts)} {if isset($LibsJSscripts) && is_array($LibsJSscripts) && !empty($LibsJSscripts)}
<!-- Additional libraries JS files --> <!-- Additional libraries JS files -->
{foreach $LibsJSscripts as $file} {foreach $LibsJSscripts as $file}
<script src="libs/{$file}" type="text/javascript"></script> <script src="libs/{$file}" type="text/javascript"></script>

View file

@ -1,7 +1,7 @@
{extends file='ls:base.tpl'} {extends file='ls:base.tpl'}
{block name="css"} {block name="css"}
<link rel="stylesheet" type="text/css" href="{css name='login.css'}" media="screen" title="Normal" /> <link rel="stylesheet" type="text/css" href="{css name='login.css'}" media="screen" title="Normal" />
{include file='ls:LSsession_css.tpl'} {include file='ls:css.tpl'}
{/block} {/block}
{block name="body"} {block name="body"}
<div class='loginform'> <div class='loginform'>

View file

@ -1,7 +1,7 @@
{extends file='ls:base.tpl'} {extends file='ls:base.tpl'}
{block name="css"} {block name="css"}
<link rel="stylesheet" type="text/css" href="{css name='recoverpassword.css'}" media="screen" title="Normal" /> <link rel="stylesheet" type="text/css" href="{css name='recoverpassword.css'}" media="screen" title="Normal" />
{include file='ls:LSsession_css.tpl'} {include file='ls:css.tpl'}
{/block} {/block}
{block name="body"} {block name="body"}
<div class='recoverpasswordform'> <div class='recoverpasswordform'>