ServerLayoutSaveButtonScript.script 2.73 KB
Newer Older
Darming's avatar
Darming committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
window['${/parameter/@bp_seq}${/parameter/@layout_code}_SAVE_LAYOUT_DYNAMIC_CLICK']=function(nextStep){
	window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
	var root_ds=$('${/parameter/@bp_seq}${/parameter/@layout_code}_virtual_ds');
	window['${/parameter/@layout_code}_ignore_required_before_save']();
    if (root_ds.validate()) {
        var winid = '${/parameter/@winid}';
        var root_record = root_ds.getCurrentRecord();
        root_ds.setSubmitParameter('layout_code', '${/parameter/@layout_code}');
        function ON_LAYOUT_DYNAMIC_BEFORE_SAVE(){
        	root_ds.un('beforesubmit',ON_LAYOUT_DYNAMIC_BEFORE_SAVE);
        	var flag = false;
        	for (var name in root_record.data) {
                if (root_record.data[name].data[0].ds && root_record.data[name].data[0].ds instanceof $L.DataSet) {
                    var current_record = root_record.data[name].data[0].ds.getCurrentRecord();
                    flag = window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_before_submit'](root_record.data[name].data[0].ds, current_record);
                }
            }
            if(!flag){
            	UN_SUBMIT_REF_FUNCTION();
            }
			window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        	return flag;
        }
        
        function UN_SUBMIT_REF_FUNCTION(){
			root_ds.un('submitsuccess', ON_LAYOUT_DYNAMIC_INNER_SUBMITSUCCESS);
	        root_ds.un('submitfailed', ON_LAYOUT_DYNAMIC_INNER_SUBMITFAILED);
	    	root_ds.un('submiterror', ON_LAYOUT_DYNAMIC_INNER_SUBMITERROR);
		}
	
		function ON_LAYOUT_DYNAMIC_INNER_SUBMITSUCCESS(ds, res) {
	        UN_SUBMIT_REF_FUNCTION();
	        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'](ds,root_record,res);
	        if (typeof(nextStep) == 'function') {
	            nextStep(ds);
	        }
	    }
	    function ON_LAYOUT_DYNAMIC_INNER_SUBMITFAILED(){
	    	UN_SUBMIT_REF_FUNCTION();
	    	window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
	    	
	    }
	    function ON_LAYOUT_DYNAMIC_INNER_SUBMITERROR(){
	    	UN_SUBMIT_REF_FUNCTION();
	    	window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
	    	
	    }
	    root_ds.on('beforesubmit',ON_LAYOUT_DYNAMIC_BEFORE_SAVE);
	    root_ds.on('submitsuccess', ON_LAYOUT_DYNAMIC_INNER_SUBMITSUCCESS);
	    root_ds.on('submitfailed', ON_LAYOUT_DYNAMIC_INNER_SUBMITFAILED);
	    root_ds.on('submiterror', ON_LAYOUT_DYNAMIC_INNER_SUBMITERROR);

    	root_ds.submit();
    }else{
    	window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
    }
};