Factorises promo selection.
authorStéphane Jacob <sj@m4x.org>
Mon, 6 Jun 2011 14:37:42 +0000 (16:37 +0200)
committerStéphane Jacob <sj@m4x.org>
Mon, 6 Jun 2011 19:51:06 +0000 (21:51 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
htdocs/javascript/xorg.js
templates/include/select_promo.tpl [new file with mode: 0644]
templates/newsletter/edit.tpl
templates/search/adv.form.tpl

index 7cb04c8..c05ed85 100644 (file)
@@ -839,6 +839,26 @@ function previewWiki(idFrom, idTo, withTitle, idShow)
 }
 
 // }}}
+// {{{ updatepromofields
+
+function updatepromofields(egal1, egal2, promo2) {
+    var comparator = egal1.val();
+
+    if (comparator == '=') {
+        egal2.attr('disabled', 'disabled');
+        promo2.attr('disabled', 'disabled');
+    } else if (comparator == '<=' || comparator == '>=') {
+        egal2.removeAttr('disabled');
+        promo2.removeAttr('disabled');
+        if (comparator == '<=') {
+            egal2.val('>=');
+        } else {
+            egal2.val('<=');
+        }
+    }
+}
+
+// }}}
 
 /***************************************************************************
  * Quick search
diff --git a/templates/include/select_promo.tpl b/templates/include/select_promo.tpl
new file mode 100644 (file)
index 0000000..810137b
--- /dev/null
@@ -0,0 +1,38 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2011 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  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  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<select name="{$egal1}" onchange="updatepromofields($('select[name={$egal1}]'), $('input[name={$egal2}]'), $('input[name={$promo2}]'))" style="text-align: center">
+  <option value="=" {if $promo_data.$egal1 eq "="}selected="selected"{/if}>&nbsp;=&nbsp;</option>
+  <option value="&gt;=" {if $promo_data.$egal1 eq "&gt;="}selected="selected"{/if}>&nbsp;&gt;=&nbsp;</option>
+  <option value="&lt;=" {if $promo_data.$egal1 eq "&lt;="}selected="selected"{/if}>&nbsp;&lt;=&nbsp;</option>
+</select>
+<input type="text" name="{$promo1}" size="4" maxlength="4" value="{$promo_data.$promo1}" />
+&nbsp;et&nbsp;
+<input type="text" name="{$egal2}" size="1" style="text-align:center" {if t($promo_data.$egal1) && $promo_data.$egal1 neq "="}value="{$promo_data.$egal2}"{else}value="&gt;=" disabled="disabled"{/if} readonly="readonly" />
+<input type="text" name="{$promo2}" size="4" maxlength="4" {if t($promo_data.$egal1) && $promo_data.$egal1 neq "="}value="{$promo_data.$promo2}"{else}disabled="disabled"{/if} />
+<select name="edu_type" style="text-align: center">
+  <option value="{#UserFilter::GRADE_ING#}" {if $promo_data.$edu_type eq #UserFilter::GRADE_ING#}selected="selected"{/if}>X</option>
+  <option value="{#UserFilter::GRADE_MST#}" {if $promo_data.$edu_type eq #UserFilter::GRADE_MST#}selected="selected"{/if}>Master</option>
+  <option value="{#UserFilter::GRADE_PHD#}" {if $promo_data.$edu_type eq #UserFilter::GRADE_PHD#}selected="selected"{/if}>Docteur</option>
+</select>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 2b6bcc4..3e9abf3 100644 (file)
       <tr>
         <td class="titre">Promotions</td>
         <td>
-          <script type="text/javascript">/*<![CDATA[*/
-            {literal}
-            function updatepromofields(egal1) {
-              var f = egal1.form;
-              f.egal2.disabled = f.promo2.disabled = egal1.value == '=';
-              f.egal2.readOnly = true;
-              if (f.egal1.value == '>=') {
-                f.egal2.value = '<=';
-              } else {
-                f.egal2.value = '>=';
-              }
-            }
-            $(function() { updatepromofields($('select[name=egal1]')[0]); });
-            {/literal}
-          /*]]>*/</script>
-          <select name="egal1" onchange="updatepromofields(this)" style="text-align:center">
-            <option value="=" {if $smarty.request.egal1 eq "="}selected="selected"{/if}>&nbsp;=&nbsp;</option>
-            <option value="&gt;=" {if $smarty.request.egal1 eq "&gt;="}selected="selected"{/if}>&nbsp;&gt;=&nbsp;</option>
-            <option value="&lt;=" {if $smarty.request.egal1 eq "&lt;="}selected="selected"{/if}>&nbsp;&lt;=&nbsp;</option>
-          </select>
-          <input type="text" name="promo1" size="4" maxlength="4" value="{$smarty.request.promo1}" />
-          &nbsp;et&nbsp;
-          <input type="text" name="egal2" size="1" style="text-align:center" value="{if t($smarty.request.egal2) eq '&lt;'}&lt;{else}&gt;{/if}" readonly="readonly" />
-          <input type="text" name="promo2" size="4" maxlength="4" value="{$smarty.request.promo2}" />
-          <select name="edu_type" style="text-align:center">
-            <option value="{#UserFilter::GRADE_ING#}" {if $smarty.request.edu_type eq #UserFilter::GRADE_ING#}selected="selected"{/if}>X</option>
-            <option value="{#UserFilter::GRADE_MST#}" {if $smarty.request.edu_type eq #UserFilter::GRADE_MST#}selected="selected"{/if}>Master</option>
-            <option value="{#UserFilter::GRADE_PHD#}" {if $smarty.request.edu_type eq #UserFilter::GRADE_PHD#}selected="selected"{/if}>Docteur</option>
-          </select>
+          {include file="include/select_promo.tpl" promo_data=$smarty.request egal1="egal1" egal2="egal2" promo1="promo1" promo2="promo2" edu_type="edu_type"}
         </td>
       </tr>
       {/if}
index ba7e7a5..a26d835 100644 (file)
@@ -335,35 +335,7 @@ function cleanForm(f) {
     <tr>
       <td>Promotion</td>
       <td>
-        <script type="text/javascript">/*<![CDATA[*/
-          {literal}
-          function updatepromofields(egal1) {
-            var f = egal1.form;
-            f.egal2.disabled = f.promo2.disabled = egal1.value == '=';
-            f.egal2.readOnly = true;
-            if (f.egal1.value == '>=') {
-              f.egal2.value = '<=';
-            } else {
-              f.egal2.value = '>=';
-            }
-          }
-          $(function() { updatepromofields($('select[name=egal1]')[0]); });
-          {/literal}
-        /*]]>*/</script>
-        <select name="egal1" onchange="updatepromofields(this)" style="text-align:center">
-          <option value="=" {if $smarty.request.egal1 eq "="}selected="selected"{/if}>&nbsp;=&nbsp;</option>
-          <option value="&gt;=" {if $smarty.request.egal1 eq "&gt;="}selected="selected"{/if}>&nbsp;&gt;=&nbsp;</option>
-          <option value="&lt;=" {if $smarty.request.egal1 eq "&lt;="}selected="selected"{/if}>&nbsp;&lt;=&nbsp;</option>
-        </select>
-        <input type="text" name="promo1" size="4" maxlength="4" value="{$smarty.request.promo1}" />
-        &nbsp;et&nbsp;
-        <input type="text" name="egal2" size="1" style="text-align:center" value="{if t($smarty.request.egal2) eq '&lt;'}&lt;{else}&gt;{/if}" readonly="readonly" />
-        <input type="text" name="promo2" size="4" maxlength="4" value="{$smarty.request.promo2}" />
-        <select name="edu_type" style="text-align:center">
-          <option value="{#UserFilter::GRADE_ING#}" {if $smarty.request.edu_type eq #UserFilter::GRADE_ING#}selected="selected"{/if}>X</option>
-          <option value="{#UserFilter::GRADE_MST#}" {if $smarty.request.edu_type eq #UserFilter::GRADE_MST#}selected="selected"{/if}>Master</option>
-          <option value="{#UserFilter::GRADE_PHD#}" {if $smarty.request.edu_type eq #UserFilter::GRADE_PHD#}selected="selected"{/if}>Docteur</option>
-        </select>
+        {include file="include/select_promo.tpl" promo_data=$smarty.request egal1="egal1" egal2="egal2" promo1="promo1" promo2="promo2" edu_type="edu_type"}
       </td>
     </tr>
     <tr>