Dojo DateTextBox选择的值不应清除

时间:2019-01-11 05:53:56

标签: dojo

我有一个要求,我要在DateTextBox中选择“开始日期”和“结束日期”。 (DateTextBox是使用dojo以编程方式编写的)。我想限制/避免从清除/重置开始日期和到日期。当我们单击“保存”按钮时,日期就会过去。 下面是jsp代码。

<script>
require(["dojo/topic",
         "strataModules/DisplayTable",
         "strataModules/URL",
          "strataModules/SecuredTableContainer",
         "dijit/form/TextBox",
         "dijit/form/CheckBox",
         "dijit/form/NumberSpinner",  
         "dijit/form/DateTextBox",
         "strataModules/Select",
         "dstore/RequestMemory",
         'dstore/Memory',
         "dstore/legacy/DstoreAdapter",
         "dojox/mvc/at",
         'strataModules/StrataTabLayout', 
         'dojo/request/notify','dojo/_base/declare'], 
    function(topic, DisplayTable, URL,TableContainer, TextBox, CheckBox, NumberSpinner,DateTextBox, Select, RequestMemory, Memory, DstoreAdapter, at, StrataTabLayout, notify,declare){

        var tab = StrataTabLayout.getTab('${param.pageId}');        
        var modelController = tab.getModel();
        modelController.set('emitChanges', false);
        var handle = notify('stop', function(){
            handle.remove()
            modelController.set('emitChanges', true);
        });
        var model = modelController.getModel();
        var funDefinitionTableArea = tab.bySelector('.funDefinitionTableArea');               
        var resultAttributesTableArea = tab.bySelector('.resultAttributesTableArea');


        var CustomSelect = declare(Select, {
            _setDisplay: function(newDisplay) {
                newDisplay = newDisplay.substr(0, newDisplay.lastIndexOf('('));
                this.inherited(arguments);
                }
        });


        var CustmSelect = declare(Select, {
            _setDisplay: function(newDisplay) {
                var attrDescr = this._getSelectedOptionsAttr().item.attrDescr;
                var length = attrDescr.indexOf('(');
                if(length == -1) {
                    length = attrDescr.length;
                    }
                newDisplay = attrDescr.substr(0, length).trim();
                this.inherited(arguments);
                }      
        });   

        var funDefinitionTable = new TableContainer({
            authRight:'${AuthRights.EDIT_FUNCTIONS}',
            authSysId: tab.context.sysId,
            authVerId: tab.context.versionNum,
            cols: 2,
            customClass:"funLabelsValues",
            labelWidth: '150'
        });

        var resultAttributesTable = new TableContainer({
            authRight:'${AuthRights.EDIT_FUNCTIONS}',
            authSysId: tab.context.sysId,
            authVerId: tab.context.versionNum,
            cols: 2,
            customClass:"funLabelsValues",
            labelWidth: '150'
        });



        var txtFnId = new TextBox({
            uppercase: true,
            maxlength: ${strataRuntimeProperties.components.maxIdCharacter},
            style: 'width: 200px',
//          disabled: (${isAdd} ? false : true),
            label: "<span class='required'><s:message code="common.field.id.label"/></span>", 
            value: at('rel:', 'fnId'),
            tabIndex: 1
        });
        txtFnId.own(topic.subscribe('strata/'+tab.id+'/event/component/button/add', function(){
            txtFnId.set('disabled', false);
            txtFnId.focus();
        }));
        txtFnId.own(topic.subscribe('strata/'+tab.id+'/event/component/button/saveAs', function(){
            txtFnId.set('disabled',false);
            txtFnId.focus();
        }));
        /*txtFnId.own(topic.subscribe('strata/'+tab.id+'/event/component/button/save', function(){
            txtFnId.set('disabled',false);
        }));*/
        txtFnId.own(topic.subscribe("strata/"+tab.id+"/event/component/button/newRevision", function(){
            txtFnId.set("disabled",true);
        }));

        var slcTreeType = new Select ({
            labelAttr : 'displayValue',
            valueAttr: 'id',
            selectedValue: '${function.iterativeInd}',
            defaultBlank: true,
            style: 'width: 200px',
            label: '<span class="required"><s:message code="functions.decisionTree.field.treeType.label"/></span>',
            targetURL: '<c:url value="/rs/configuration/types/iterativeInd/codes"/>',
            value: at('rel:', 'iterativeInd'),
            selectedValue: '${function.iterativeInd}',
            tabIndex: 2
        });
        slcTreeType.own(topic.subscribe("strata/"+tab.id+"/event/component/button/add", function(){
            slcTreeType.set("value", "N");
        }));

        var txtDescr = new TextBox({
            maxlength: ${strataRuntimeProperties.components.maxDescrCharacter},
            style: 'width: 200px',
            label: '<span class="required"><s:message code="common.field.description.label"/></span>',
            disabled: (${revisionId=="PRODUCTION"} ? false : true),
            value: at('rel:', 'descr'),
            tabIndex: 3
        }, 'txtDescr');
        txtDescr.own(topic.subscribe("strata/"+tab.id+"/event/component/button/add", function(){
            txtDescr.set("value", "");
        }));            
        txtDescr.own(topic.subscribe("strata/"+tab.id+"/event/component/button/newRevision", function(){
            txtDescr.set("disabled",true);
        }));
        txtDescr.own(topic.subscribe("strata/"+tab.id+"/event/component/button/save", function(){
            txtDescr.set("disabled",false);
        }));

        var chkPopAudiAttrInd = new CheckBox({
            label:'<span class="notRequired"><s:message code="functions.field.populateAuditAttr.label"/>',          
            value: at('rel:', 'treeAttrInd'),
            checked: at('rel:', 'treeAttrInd'),
            // RV STRATA52 STRATAD-14 12/26/2018 START - adjusting the tab indicator due to two new effective from and to date fields 
            tabIndex: 9
            //RV STRATA52 STRATAD-14 END
        }); 
        chkPopAudiAttrInd.own(topic.subscribe("strata/"+tab.id+"/event/component/button/add", function(){
            chkPopAudiAttrInd.set("Checked", false);
        }));        

        var txtRevision = new TextBox({
            disabled: true,
            uppercase: true,
            maxlength: ${strataRuntimeProperties.components.maxRevisionCharacter},
            style: 'width: 200px',
            label: '<span class="notRequired"><s:message code="common.field.revision.label"/>',
            value: at('rel:', 'revisionId'),
            tabIndex: 5
        } ,'txtRevision');
        txtRevision.own(topic.subscribe("strata/"+tab.id+"/event/component/button/newRevision", function(){
            txtRevision.set("disabled", false);
            txtRevision.focus();
        }));
        txtRevision.own(topic.subscribe("strata/"+tab.id+"/event/component/button/save", function(){
            txtRevision.set("disabled",true);
        }));

        var nmbrTeeResAttrCount = new NumberSpinner({
            smallDelta: 1,
            value: at('rel:', 'treeResultAttr'),
            selectedValue: "${function.treeResultAttr}",
            constraints: { min:0, max:2, places:0 },
            style: 'width: 70px',
            label: '<span class="notRequired"><s:message code="functions.decisionTree.field.treeResAttr.label"/>',
            intermediateChanges: true ,
            tabIndex: 6
        }); 
        nmbrTeeResAttrCount.own(topic.subscribe("strata/"+tab.id+"/event/component/button/add", function(){
            nmbrTeeResAttrCount.set("value" ,"0");  
        }));

        //dropdown filters for Results
        var slcNumIterAttr = new CustomSelect({
            labelAttr : 'displayValue',
            valueAttr: 'id',                
            defaultBlank: true,
            maxHeight: '300',
            style: 'width: 200px',
            value: at('rel:', "iterAttr"),
            disabled: ('${function.iterativeInd}' =='N' ? true : false),    
            selectedValue: "${function.iterAttr}",
            targetURL: URL.toURL('<c:url value="/rs/versions/'+tab.context.sysVersionUoid+'/attributes/iteration/codes"/>').href(),           
            label: '<span class="notRequired"><s:message code="functions.field.noOfIterAttr.label"/>',
            tabIndex: 4
        });  

        var decRptStore = new RequestMemory({
            idProperty : 'id',
            target: URL.toURL('<c:url value="/rs/versions/'+tab.context.sysVersionUoid+'/attributes/codes"/>')
                .addParam('compType', 'D').addParam('attrType','A').addParam('length',8).href()
        }); 


        // KM Strata50 FUTS STRAT00030139 05/17/16 Start - Added the values in the store and then sort it so that the added value can be seen in the drop-down.

        var filteredDecStore = new DstoreAdapter(new Memory({idProperty: 'id'}));
            filteredDecStore.put({id:'<s:message code="functions.select.resAttr.options.decsind"/>', displayValue:'<s:message code="functions.select.resAttr.option.decsind"/>'});

        var filteredRptStore = new DstoreAdapter(new Memory({idProperty: 'id'}));
            filteredRptStore.put({id:'<s:message code="functions.select.resAttr.options.rptgrp"/>', displayValue:'<s:message code="functions.select.resAttr.option.rptgrp"/>'});

        var slcDecisionAttr = new CustomSelect({
            labelAttr : 'displayValue',
            valueAttr: 'id',
            sortByLabel:true,
            //store: filteredDecStore,
            style: 'width: 200px',
            maxHeight: '300',
            selectedValue: "${function.decisionAttr}",
            defaultBlank: true,
            value: at('rel:', "decisionAttr"),                              
            label: "<span class='required'><s:message code="functions.decisionTree.field.decisionAttr.label"/></span>",
        // RV STRATA52 STRATAD-14 12/26/2018 START - adjusting the tab indicator due to two new effective from and to date fields
            tabIndex: 10
        //RV STRATA52 STRATAD-14 END 
        });


        // RV STRATA52 STRATAD-14 12/26/2018 START - fetching the value of process mode indicator from context and added new dojo calendar date fields for effective from and to date
        var processModeInd = tab.getContext('processInd');
        var effectiveFromDate = new DateTextBox({
            name: "effectiveFromDate",
            label: '<span class="notRequired"><s:message code="functions.decisionTree.field.effFromDate.label"/>',  
            disabled: model.revisionId=="PRODUCTION" || processModeInd=="B" || processModeInd=="O" ? true : false,
            value: at('rel:', 'effectiveFromDate'), 
            tabIndex: 7
        },'effectiveFromDate');
        //effectiveFromDate.textbox.readOnly = true;

        var effectiveToDate = new DateTextBox({
            name: "effectiveToDate",
            label: '<span class="notRequired"><s:message code="functions.decisionTree.field.effToDate.label"/>',                        
            disabled: model.revisionId=="PRODUCTION" ||processModeInd=="B" || processModeInd=="O" ? true : false ,
            value: at('rel:', 'effectiveToDate'),           
            tabIndex: 8
        } ,'effectiveToDate');

        //effectiveToDate.textbox.readOnly = true;
        effectiveFromDate.own(topic.subscribe("strata/"+tab.id+"/event/component/button/newRevision", function() {
            effectiveFromDate.set("disabled", !(processModeInd == 'J'));
            effectiveToDate.set("disabled", !(processModeInd == 'J')); 

            if (processModeInd == 'J'){         
                effectiveFromDate.set("value", null); 
                effectiveToDate.set("value", null); 
            }
        }));

        //RV STRATA52 STRATAD-14 END    
        // RV STRATA52 STRATAD-148 01/04/2018 START - disablling the effective from and to date fields for save as functions
        effectiveFromDate.own(topic.subscribe('strata/'+tab.id+'/event/component/button/saveAs', function(){
            effectiveFromDate.set('disabled',true);
            effectiveToDate.set('disabled',true);
            effectiveFromDate.set("value", null); 
            effectiveToDate.set("value", null); 
        }));
        //RV STRATA52 STRATAD-148 END

        var slcRptGrpAttr = new CustomSelect({
            labelAttr : 'displayValue',
            valueAttr: 'id',
            sortByLabel:true,
            style: 'width: 200px',
            maxHeight: '300',
            selectedValue: "${function.rptGrpAttr}",
            value: at('rel:', "rptGrpAttr"),
            defaultBlank: true,             
            label: "<span class='required'><s:message code="functions.decisionTree.field.rptGrpAttr.label"/></span>",
         // RV STRATA52 STRATAD-14 12/26/2018 START - adjusting the tab indicator due to two new effective from and to date fields
            tabIndex: 12
          //RV STRATA52 STRATAD-14 END 
        }); 


         decRptStore.forEach(function(item){
             filteredDecStore.put(item);
             filteredRptStore.put(item);
             }).then(function(results) {
                 slcDecisionAttr.setStore(filteredDecStore);
                 slcRptGrpAttr.setStore(filteredRptStore);
                 });

        // KM Strata50 FUTS STRAT00030139 End

         var treeResultStore = new RequestMemory({
             idProperty : 'uoid',
             target: URL.toURL('<c:url value="/rs/versions/${function.sysVersionUoid}/attributes/substr"/>')
                .addParam('compType','D').addParam('attrType','ALL').href()
        }); 

        treeResultStore.put({uoid: null, attrId:"&nbsp;" , attrDescr: "&nbsp;", attrSubstringUoid: null});

        var treeResultDStore = new DstoreAdapter(treeResultStore)

        var slcTreeResultAttr1 = new CustmSelect({
            labelAttr: 'attrDescr',
            valueAttr: 'uoid',
            defaultBlank: true,
            maxHeight: '300',
            style: 'width: 200px',
            selectedValue: "${function.treeResultAttr1}",
            value: at('rel:', "treeResultAttr1"),           
            disabled: ((${function.treeResultAttr=='1'} ||${function.treeResultAttr=='2'}) ? false : true) ,
            store: treeResultDStore,
            label: '<span class="notRequired"><s:message code="functions.decisionTree.field.treeResultAttr1.label"/>',
         // RV STRATA52 STRATAD-14 12/26/2018 START - adjusting the tab indicator due to two new effective from and to date fields
            tabIndex: 11
            //STRATA52 STRATAD-14 END
        });

        var slcTreeResultAttr2 = new CustmSelect({
            labelAttr: 'attrDescr',
            valueAttr: 'uoid',              
            defaultBlank: true,
            maxHeight: '300',
            style: 'width: 200px',
            disabled: ((${function.treeResultAttr=='2'}) ? false : true) ,
            selectedValue: "${function.treeResultAttr2}",
            value: at('rel:', "treeResultAttr2"),
            store: treeResultDStore,
            label: '<span class="notRequired"><s:message code="functions.decisionTree.field.treeResultAttr2.label"/>',
            // RV STRATA52 STRATAD-14 12/26/2018 START - adjusting the tab indicator due to two new effective from and to date fields
            tabIndex: 13
            //STRATA52 STRATAD-14 END
         });

        //item change
        slcTreeType.onChange = function(selValue) {
            if(selValue == 'N') {
                slcNumIterAttr.set('value', '');
            }
            slcNumIterAttr.set('disabled', selValue == 'N' ? true : false);
            };  

        nmbrTeeResAttrCount.onChange = function(newValue) {
            if (newValue==0) {
                slcTreeResultAttr1.set('value', '');
                slcTreeResultAttr2.set('value', '');
                slcTreeResultAttr1.set('disabled', true);
                slcTreeResultAttr2.set('disabled', true);
            } else if (newValue==1) {
                slcTreeResultAttr1.set('disabled', false);
                slcTreeResultAttr2.set('value', '');
                slcTreeResultAttr2.set('disabled', true);
            } else if (newValue==2) {
                slcTreeResultAttr1.set('disabled', false);
                slcTreeResultAttr2.set('disabled', false);
            } else if(isNaN(newValue)) {
                model.treeResultAttr = null;
            } 
        };

        if (model.revisionId == 'PRODUCTION'){
            txtFnId.set('disabled',false);
        }else{
            txtFnId.set('disabled',true);
        }

        //for effective date on change  
        /*
        effectiveToDate.onChange = function(Value) {
            if(selValue == 'N') {
                slcNumIterAttr.set('value', '');
            }
            slcNumIterAttr.set('disabled', selValue == 'N' ? true : false);
            };  */

        //1st section - Function Definition
        funDefinitionTable.addChild(txtFnId);
        funDefinitionTable.addChild(slcTreeType);
        funDefinitionTable.addChild(txtDescr);
        funDefinitionTable.addChild(slcNumIterAttr); 
        funDefinitionTable.addChild(txtRevision);
        funDefinitionTable.addChild(nmbrTeeResAttrCount);
     // RV STRATA52 STRATAD-14 12/26/2018 START - added effective from and to date calendar date fields as a child into funDefinitionTable
        funDefinitionTable.addChild(effectiveFromDate);
        funDefinitionTable.addChild(effectiveToDate);
      //RV STRATA52 STRATAD-14 END
        funDefinitionTable.addChild(chkPopAudiAttrInd); 

        funDefinitionTable.placeAt(funDefinitionTableArea);
        funDefinitionTable.startup();   

        //2nd section - Result Attribute
        resultAttributesTable.addChild(slcDecisionAttr);
        resultAttributesTable.addChild(slcTreeResultAttr1);
        resultAttributesTable.addChild(slcRptGrpAttr);
        resultAttributesTable.addChild(slcTreeResultAttr2);        

        resultAttributesTable.placeAt(resultAttributesTableArea);
        resultAttributesTable.startup();

        dojo.addOnLoad(function() {
            if(!txtFnId.disabled) { 
                txtFnId.focus();    //set focus when add link clicked
                txtFnId.textbox.setSelectionRange(txtFnId.value.length, txtFnId.value.length);
            }
        }); 
    });
</script>

先谢谢了:)

0 个答案:

没有答案