Changeset 419 for tapas/web


Ignore:
Timestamp:
03/19/12 17:06:58 (12 years ago)
Author:
rboipsl
Message:

creation listes dans form
creation class Observatory

Location:
tapas/web
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tapas/web/project/formTapas.jsp

    r406 r419  
    77<tiles:insert page="/resources/templates/templateEther.jsp" flush="true"> 
    88 
    9     <tiles:put name="insertCss" type="string"/> 
     9    <tiles:put name="insertCss" type="string"> 
     10        <ether:htmlCss cssFile="select"/> 
     11    </tiles:put> 
    1012    <tiles:put name="insertJsOrJsp" type="string"> 
    1113        <ether:htmlJs jsFile="library/jquery.json-2.3"/> 
     14        <ether:htmlJs jsFile="classesForJQuery/Select"/> 
    1215        <ether:htmlJsp jspFile="formTapas_script"/> 
    1316    </tiles:put> 
     
    3336            tapasTexts["<%=WebException.WebCode.ERROR_JSON_TAPAS_IS_NULL%>"] = "<spring:message code="error.ERROR_JSON_TAPAS_IS_NULL"/>"; 
    3437 
    35             var interfaceTapas = new InterfaceTapas(); 
     38            var interfaceTapas = new InterfaceTapas(${jSonFileFormats},${jSonYesNos}); 
    3639        </script> 
    3740 
  • tapas/web/project/formTapas_script.jsp

    r415 r419  
    22    var InterfaceTapas = Class.create( { 
    33 
    4         initialize: function() 
     4        initialize: function(jsonFileFormats,jsonYesNos) 
    55        { 
    66            /** *********** CONTAINERS *********** **/ 
     
    88            this.containerErrors = $( "#errors" ); 
    99 
     10            this.jsonFileFormats = jsonFileFormats || null; 
     11            this.jsonYesNos = jsonYesNos || null; 
     12 
    1013            this.containerErrors.hide(); 
     14 
    1115            this.createForm(); 
    1216        }, 
    1317 
     18 
     19 
    1420        // CREATES ******************************************************** 
     21        createTr: function(texte, inputId, container) 
     22        { 
     23            var tr=$( document.createElement("tr") ); 
     24            var td1=$( document.createElement("td") ); 
     25            var td2=$( document.createElement("td") ); 
     26            var input=$( document.createElement("input") ); 
     27 
     28 
     29            input.attr({id: inputId}); 
     30            td1.html(texte); 
     31            tr.append(td1); 
     32            td2.append(input); 
     33            tr.append(td2); 
     34            container.append(tr); 
     35        }, 
     36 
     37 
     38        createTrList: function(texte, inputId, container, type) 
     39                { 
     40                    var tr=$( document.createElement("tr") ); 
     41                    var td1=$( document.createElement("td") ); 
     42                    var td2=$( document.createElement("td") ); 
     43                    var input=$( document.createElement("input") ); 
     44 
     45 
     46                    input.attr({id: inputId}); 
     47                    td1.html(texte); 
     48                    tr.append(td1); 
     49                    if (type == 'format') this.displayFileFormats(td2); 
     50                    else if (type == 'yesno') this.displayYesNo(td2); 
     51 
     52                    tr.append(td2); 
     53                    container.append(tr); 
     54                }, 
     55 
     56 
    1557        createForm: function() 
    1658        { 
    17             // Create button elements 
    18             this.input1 = $( document.createElement( "input" ) ); 
    19             var input2 = $( document.createElement( "input" ) ); 
    20  
    21             this.input1.attr( {id:"1"} ); 
    22             this.containerForm.append( this.input1 ); 
    23  
    24             input2.attr( {id:"2"} ); 
    25             this.containerForm.append( input2 ); 
    26  
     59 
     60            //Creation div 
     61            var divPreference=$( document.createElement("div") ); 
     62            var tabPreference=$( document.createElement("table") ); 
     63 
     64            this.createTrList("File format", "p1", tabPreference, 'format'); 
     65            this.createTr("Rayleigh extinction", "p2", tabPreference); 
     66            this.createTrList("H20 extinction", "p3", tabPreference, 'yesno'); 
     67            this.createTrList("O3 extinction", "p4", tabPreference, 'yesno'); 
     68            this.createTrList("O2 extinction", "p5", tabPreference, 'yesno'); 
     69            this.createTrList("CO2 extinction", "p6", tabPreference, 'yesno'); 
     70 
     71            divPreference.append( tabPreference ); 
     72            this.containerForm.append( divPreference ); 
     73 
     74            //jQuery.proxy permet d'envoyer le contexte this courant 
    2775            var submitButton = new Button( {value:tapasTexts["label.submitButton"], parent:this.containerForm, id:"button_submit", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickSubmit, this )} ); 
    2876 
    2977        }, 
     78 
     79 
    3080 
    3181        // REQUESTS ******************************************************** 
     
    59109        }, 
    60110 
     111 
    61112        // OTHERS ******************************************************** 
     113        displayFileFormats: function(container) 
     114        { 
     115            var paramSelect = new Object(); 
     116            paramSelect.id = "select_formats"; 
     117            paramSelect.parent = container; 
     118            this.selectFormats = new Select( paramSelect ); 
     119            jQuery.each( this.jsonFileFormats, jQuery.proxy( function ( i, jsonFileFormat ) 
     120            { 
     121                this.selectFormats.add( jsonFileFormat.value, jsonFileFormat.text ); 
     122            }, this ) ); 
     123            this.selectFormats.selectFirst( false ); 
     124        }, 
     125 
     126 
     127        displayYesNo: function(container,name) 
     128        { 
     129            var paramSelect = new Object(); 
     130            paramSelect.id = "select_"+name; 
     131            paramSelect.parent = container; 
     132            this.selectYesNos = new Select( paramSelect ); 
     133            jQuery.each( this.jsonYesNos, jQuery.proxy( function ( i, jsonYesNo ) 
     134            { 
     135                this.selectYesNos.add( jsonYesNo.value, jsonYesNo.text ); 
     136            }, this ) ); 
     137            this.selectYesNos.selectFirst( false ); 
     138        }, 
     139 
     140 
    62141        showErrors: function( result ) 
    63142        { 
  • tapas/web/src/com/ether/Controller.java

    r416 r419  
    55import com.ether.annotation.ParamName; 
    66import com.ether.annotation.UseJSON; 
     7import com.ether.tapas.Observatory; 
    78import com.ether.tapas.Tapas; 
     9import com.ether.user.UserRole; 
    810import net.sf.json.JSONObject; 
    911import org.apache.commons.logging.Log; 
    1012import org.apache.commons.logging.LogFactory; 
    1113 
     14import java.util.ArrayList; 
    1215import java.util.HashMap; 
     16import java.util.List; 
    1317import java.util.Map; 
    1418 
     
    2529    /** *********************************************************** **/ 
    2630    @ControllerMethod(view = VIEW_FORM_TAPAS, loginMandatory = true, defaultView = VIEW_INDEX) 
    27     public Map<String, Object> viewForm() 
     31    public JSONObject viewForm() 
    2832            throws WebException 
    2933    { 
    30         return new HashMap<String, Object>(); 
     34 
     35        try 
     36        { 
     37            final List<Observatory> allObservatories = getTapasService().getAllObservatories(); 
     38 
     39            final JSONObject jsonObject = new JSONObject(); 
     40            jsonObject.put( "jSonFileFormats", getJSONFileFormat() ); 
     41            jsonObject.put( "jSonYesNos", getJSONYesNo() ); 
     42            jsonObject.put( "jSonObservatories", allObservatories ); 
     43            return jsonObject; 
     44        } 
     45        catch( ServiceException e ) 
     46        { 
     47            throw new WebException( WebException.WebCode.ERROR_NO_OBSERVATORY_FOUND, e ); 
     48        } 
     49 
    3150    } 
     51 
     52 
     53 
     54 
    3255 
    3356    /** *********************************************************** **/ 
     
    4972    } 
    5073 
     74    private List<JSONObject> getJSONFileFormat() 
     75    { 
     76        final FileFormat[] fileFormats = FileFormat.values(); 
     77 
     78        final List<JSONObject> jsonFileFormats = new ArrayList<JSONObject>( fileFormats.length ); 
     79 
     80        for( final FileFormat fileFormat : fileFormats ) 
     81        { 
     82            final JSONObject jsonFileFormat = new JSONObject(); 
     83            jsonFileFormat .put( "text", fileFormat.name() ); 
     84            jsonFileFormat .put( "value", fileFormat.name() ); 
     85            jsonFileFormats.add( jsonFileFormat  ); 
     86        } 
     87        return jsonFileFormats; 
     88    } 
     89 
     90    private List<JSONObject> getJSONYesNo() 
     91    { 
     92        final YesNo[] yesNos = YesNo.values(); 
     93 
     94        final List<JSONObject> jsonYesNos = new ArrayList<JSONObject>( yesNos.length ); 
     95 
     96        for( final YesNo yesNo : yesNos ) 
     97        { 
     98            final JSONObject jsonYesNo = new JSONObject(); 
     99            jsonYesNo .put( "text", yesNo.name() ); 
     100            jsonYesNo .put( "value", yesNo.name() ); 
     101            jsonYesNos.add( jsonYesNo ); 
     102        } 
     103        return jsonYesNos; 
     104    } 
     105 
    51106    private static final Log LOGGER = LogFactory.getLog( Controller.class ); 
    52107 
  • tapas/web/src/com/ether/WebException.java

    r416 r419  
    4444        USER_ALREADY_EXISTS, 
    4545        ERROR_ENCRYPT_PASSWORD, 
    46         ERROR_EMAIL_CANNOT_BE_SEND 
     46        ERROR_EMAIL_CANNOT_BE_SEND, 
     47        ERROR_NO_OBSERVATORY_FOUND 
    4748    } 
    4849 
Note: See TracChangeset for help on using the changeset viewer.