con_contract_update_form.js 4.46 KB
Newer Older
Spencer Chang's avatar
Spencer Chang 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
var config = $config();
function isEmpty(v) {
	return v == null || typeof (v) == 'undefined';
}

function newMap(name) {
	return new CompositeMap("a", 'http://www.leaf-framework.org/application',
			name);
}

function createFields() {
	var fields = newMap('fields');
	var layout_config_path = $ctx.get('/model/layout_config_path');
//	println(layout_config_path.toXML())
//	println("------------")
	var layout_configs = layout_config_path.getChildren();
	for ( var i = 0; i < layout_configs.length; i++) {
		var f = newMap('field');
		f.name = layout_configs[i].column_name;
		if (f.name == 'DIV')
			continue;
		if (!isEmpty(layout_configs[i].default_value))
			f.defaultvalue = layout_configs[i].default_value;
		if (layout_configs[i].validation_type == 'LOV') {
			var f1 = newMap('field');
			f1.name = layout_configs[i].column_name + '_lovname';
			if (!isEmpty(layout_configs[i].default_value_name))
				f1.defaultvalue = layout_configs[i].default_value_name;
			f1.lovgridheight = '350';
			f1.lovheight = '500';
			f1.lovservice = 'hls.HLS500.hls_parameters_lov';
			f1.lovwidth = '500';
			f1.readonly = String(layout_configs[i].readonly_input_mode);
			f1.required = String(layout_configs[i].required_input_mode);
			f1.title = layout_configs[i].prompt;
			fields.addChild(f1);
		} else if (layout_configs[i].validation_type == 'COMBOBOX') {
			var f1 = newMap('field');
			f1.name = layout_configs[i].column_name + "_comboboxname";
			if (!isEmpty(layout_configs[i].default_value_name))
				f1.defaultvalue = layout_configs[i].default_value_name;
			f1.options = $ctx.get('/parameter/@form_tab_code') + "_"
					+ layout_configs[i].column_name + "_combobox_ds";
			f1.readonly = String(layout_configs[i].readonly_input_mode);
			f1.required = String(layout_configs[i].required_input_mode);
			f1.title = layout_configs[i].prompt;
			fields.addChild(f1);
		} else if (layout_configs[i].validation_type == 'CHECKBOX') {
			f.checkedvalue = 'Y';
			f.uncheckedvalue = 'N';
		} else {
			f.readonly = String(layout_configs[i].readonly_input_mode);
			f.required = String(layout_configs[i].required_input_mode);
		}
		fields.addChild(f);
	}
	return fields;
}

function createDs_1() {
	var dataSet = newMap("dataSet");
	dataSet.id = "temp_ds";
	dataSet.processfunction = "temp_processfunction";
	dataSet.autocreate = 'true'
	var fs = createFields();

	dataSet.addChild(fs);

	var events = newMap('events');
	var event = newMap('event');
	event.name = 'add';
	event.handler = 'temp_Load';
	events.addChild(event);
	dataSet.addChild(events);
	return dataSet;
}

function createDs_2(parent_table_flag) {
	var dataSet = newMap('dataSet');
	dataSet.id = $ctx.get('/model/tab_layout_detail_path/record/@base_table')
			+ "_ds";
	dataSet.autocreate = 'true';
	if (parent_table_flag == 'Y') {
		dataset.bindname = $ctx.get('/parameter/@form_tab_code') + "_"
				+ $ctx.get('/model/tab_layout_detail_path/record/@base_table');
		dataSet.bindtarget = $ctx
				.get('/model/tab_layout_detail_path/record/@parent_table')
				+ "_ds";
	}
	dataSet.queryurl = $ctx.get('/request/@context_path')
			+ "/modules/cont/CON500/con_contract_base_query.lsc"
			+ "?document_id=" + $ctx.get('/parameter/@document_id')
			+ "&document_category=" + $ctx.get('/parameter/@document_category')
			+ "&document_type=" + $ctx.get('/parameter/@document_type')
			+ "&tab_code=" + $ctx.get('/parameter/@form_tab_code')
			+ "&layout_code=" + $ctx.get('/parameter/@layout_code');
	dataSet.submiturl = $ctx.get('/request/@context_path')
			+ "/modules/cont/CON500/con_contract_save.lsc" + "?base_table="
			+ $ctx.get('/model/base_table_path/record/@base_table')
			+ "&tab_code=" + $ctx.get('/parameter/@form_tab_code');
	var fields = createFields();
	dataSet.addChild(fields);
	var events = newMap('events');
	var event = newMap('event');
	// event.name = 'load';
	// event.handler = 'on_con_header_form_load';
	// events.addChild(event);
	event = newMap('event');
	event.name = 'add';
	event.handler = 'on_con_header_form_add';
	events.addChild(event);
	dataSet.addChild(events);
	return dataSet;
}

var dataSets = CompositeUtil.findChild(config, 'dataSets', 'id', 'dataSets');
var parent_tab_code_flag = $ctx
		.get('/model/tab_layout_detail_path/record/@parent_tab_code_flag');
if (parent_tab_code_flag == 'N') {
	var ds = createDs_1();
	dataSets.addChild(ds.getData());
} else if (parent_tab_code_flag == 'Y') {
	var parent_table_flag = $ctx
			.get('/model/tab_layout_detail_path/record/@parent_table_flag');
	var ds = createDs_2(parent_table_flag);
	dataSets.addChild(ds.getData());
}