PageSourceSearch

https://compman.ph/biz/js/bizobjectui.js

js compman.ph collected 2026-10-02 02:05:22 UTC 11,672 bytes, 404 lines download raw bytes

1function BizObjectUI(bizobject, callback){
2	this.bizobject = bizobject;
3	this.lookup_fields = new Object(); //associative array to define fields to show in lookup
4								//keys are field names, values are field labels
5	
6	this.new_dlg_fields = new Object(); //associative array to define fields that will
7							//be shown in adding new record
8								
9	this.order_by = "";
10	this.desc = "";
11	this.auto_no_field = "";
12	this.init_values = new Object(); //associative array to define fields which need to have initial values
13								//keys are field names, values are initial values
14
15	this.form_id = "";
16	if (callback) callback();
17}
18
19BizObjectUI.prototype.edit = function (callback){
20
21	var bizobject = this.bizobject;
22	var form_id = "";
23
24	if (this.form_id == ""){
25		alert("Form container not set for " + bizobject.table + "!");
26		console.log("BizObjectUI.edit()");
27		return;
28	}
29	
30	form_id = "#" + this.form_id + " ";
31
32	for(var key in bizobject.data){
33		$(form_id + "#" + key).val(bizobject.data[key]);
34		$(form_id + "#is_" + key).prop("checked", (bizobject.data[key] == "Y"));
35	}
36	
37	$(form_id + " #" + bizobject.table + "_id").val(bizobject.data["id"]);
38
39	if (callback)
40		callback();
41}
42
43BizObjectUI.prototype.show = function (callback){
44	
45	var bizobject = this.bizobject;
46	var form_id = "";
47
48	if (this.form_id == ""){
49		alert("Form container not set for " + bizobject.table + "!");
50		console.log("BizObjectUI.show()");
51		return;
52	}
53
54	form_id = "#" + this.form_id + " ";
55
56	for(var key in bizobject.data){
57		$(form_id + "#" + key).html(bizobject.data[key]);
58		$(form_id + "#is_" + key).prop("checked", (bizobject.data[key] == "Y"));
59	}
60
61	if (callback)
62		callback();
63	
64}
65
66BizObjectUI.prototype.form = function (container_id, callback){
67	
68	var bizobject = this.bizobject;
69	for(var key in bizobject.data){
70		if (key == 'id')
71			$(container_id).append("<input type='hidden' id='" + key + "' name='" + key + "' class='" + key + "' /><br/>");
72		else
73			$(container_id).append("<label>" + key + "</label>" +
74				"<input type='text' id='" + key + "' name='" + key + "' class='" + key + "' /><br/>");
75	}
76
77	if (callback)
78		callback();
79	
80}
81
82BizObjectUI.prototype.setFields = function (callback){
83
84	var bizobject = this.bizobject;
85	var form_id = "";
86
87	if (this.form_id == ""){
88		alert("Form container not set for " + bizobject.table + "!");
89		console.log("BizObjectUI.setFields()");
90		return;
91	}
92
93	form_id = "#" + this.form_id + " ";
94
95	for(var key in bizobject.data){
96		if (key != '' && $(form_id + "#" + key).length > 0){
97			bizobject.data[key] = $(form_id + "#" + key).val();
98		}
99	}
100	
101	if (callback) callback();
102}
103
104BizObjectUI.prototype.showLookupDiv = function (control_id, allow_add){
105	
106	var html = "";
107	html = "<table class='table-bordered table-hover table-striped table-condensed col-lg-12'>";
108	
109	//header
110	html += "<tr>";
111	for(var key in this.lookup_fields){
112		html += "<td>" + this.lookup_fields[key] + "</td>";
113	}
114
115	if ((allow_add == "" || allow_add == undefined) && allow_add != 0)
116		allow_add = 1;
117
118	if (allow_add == 1){
119		html += "<td></td>";
120	}
121
122	html += "</tr>";
123
124	//rows
125	html += "<tr>";
126	var i = 1;
127	for(var key in this.lookup_fields){
128		html += "<td><input type='text' id='" + key + "' name='" + key + "' class='col-lg-12' readonly='readonly'/></td>";
129	}
130
131	html += "<td class='text-center'>";
132	html += "<button type='button' class='btn btn-flat' id='btn_search_" + control_id + 
133		"' name='btn_search_" + control_id + "' " + "><span class='fa fa-search' style='color:white'></span></button>&nbsp;";
134
135	if (allow_add == 1){
136		html += "<button type='button' class='btn btn-flat' id='btn_new_" + control_id + 
137			"' name='btn_new_" + control_id + "' " + "><span class='fa fa-file' style='color:white'></span></button>";
138	}
139	html += "</td></tr>";
140
141	html += "</table>";
142	html += "<input type='hidden' id='" + control_id + "' name='" + control_id + "'/><br/>";
143	html += "<span id='lookup_list'></span>";
144		
145	
146	return html;
147}
148
149BizObjectUI.prototype.setupNewButton = function(control_id){
150	var bizobject = this.bizobject;
151	var bizobjectui = this;
152	$("#btn_new_" + control_id).click(
153		function (){
154			$("#new_" + control_id + "_dlg").modal();
155			bizobject.new_id();
156		});
157
158	$("#btn_add_new_" + control_id).click(
159		function (){
160			var params = "";
161			if (bizobjectui.auto_no_field != ""){
162				params += "auto_" + bizobjectui.auto_no_field + 
163					"=" + $("#auto_" + bizobjectui.auto_no_field).val() + "&";
164			}
165			for(var key in bizobjectui.new_dlg_fields){
166				params += "new_" + key + "=" + $("#new_" + key).val() + "&";
167			}			
168			for(var key in bizobjectui.init_values){
169				params += "init_" + key + "=" + $("#init_" + key).val() + "&";
170			}			
171			params += "table=" + bizobject.table;
172			$.ajax({
173				type: "POST",
174				url: "./php/dlg_add_new.php",
175				data: params,
176				success: function(data){
177					data = JSON.parse(data);
178					alert(data.message);
179					bizobject.data["id"] = data.rec_id;
180					bizobject.select();
181					$("#new_" + control_id + "_dlg").modal("hide");					
182				}
183			});
184		});
185
186}
187
188BizObjectUI.prototype.setupNewDlg = function(control_id){
189	var bizobject = this.bizobject;
190	var bizobjectui = this;
191	var html = "";
192	
193	//dialog box for new record
194	html += "<div id='new_" + control_id + "_dlg' class='modal fade' role='dialog'>";
195
196	html += "<div class='modal-dialog'>"  +
197				"<div class='modal-content'>" + 
198					"<div class='modal-header'>" +
199						"<button type='button' class='close' data-dismiss='modal'>×</button>" + 
200						"<h4 class='modal-title'>Add New Record</h4>
200" + 
201					"</div>" +
202					"<div class='modal-body'>" +
203					"<form id='form_" + control_id + "' name='form_" + control_id + "'>" +
204					"<fieldset>";
205					
206	html += "<div class='col-lg-12'><input type='hidden' id='new_" + control_id 
207		+ "' name='new_" + control_id + "'/></div>";
208	
209	var auto_no_field = this.auto_no_field;
210		
211	if (auto_no_field != "" && auto_no_field != undefined){
212		html += "<div class='controls col-lg-6 col-md-6'>" +
213			"<div class='control-group'>" +
214			"<div><input type='hidden' class='form-control input-sm' " +
215				" id='auto_" + auto_no_field + "' name='auto_" + auto_no_field + "' class='col-lg-12'/></div>" +
216			"</div>" +
217			"</div>";
218	}
219
220	//fields that must be provided with values manually
221	for(var key in this.new_dlg_fields){
222		html += "<div class='controls col-lg-6 col-md-6'>" +
223			"<div class='control-group'>" +
224			"<label class='control-label' for='input01'>" + this.new_dlg_fields[key] + "&nbsp;</label>" +
225			"<div><input type='text' class='form-control input-sm' " +
226				" id='new_" + key + "' name='new_" + key + "' class='col-lg-12'/></div>" +
227			"</div>" +
228			"</div>";
229	}
230
231	//fields that must be provided with values programmatically
232	for(var key in this.init_values){
233		html += "<div class='controls col-lg-6 col-md-6'>" +
234			"<div class='control-group'>" +
235			"<div><input type='hidden' class='form-control input-sm' " +
236				" id='init_" + key + "' name='init_" + key + "' value='" + this.init_values[key] + "' class='col-lg-12'/></div>" +
237			"</div>" +
238			"</div>";
239	}
240	
241	html += 		"</fieldset>" +
242					"</div>" +
243				"<div class='modal-footer'>" +
244				"<input type='button' class='btn btn-flat btn-success' id='btn_add_new_" + 
245					control_id + "' name='btn_add_new_" + control_id + "' value='Save'/>" +
246				"</div>" +
247				"</form>" +
248				"</div>";	
249	html += "</div>";
250	
251	return html;
252
253}
254
255BizObjectUI.prototype.setupLookup = function (lookup_div, autocomplete_field, control_id, php_file){
256	//get the columns from the lookup_fields
257	var cols = "";
258	for(var key in this.lookup_fields){
259		cols += key + ",";
260	}
261	cols = cols.substr(0, cols.length - 1);
262	
263	var bizobjectui = this;
264	var bizobject_table = bizobjectui.bizobject.table;
265	
266	var url = "";
267	if (php_file != "" && php_file != undefined)
268		url = php_file;
269	else
270		url = "./php/lookup.php";
271		
272	var order_by = (this.order_by.length > 0 ? this.order_by : "") ;
273	var desc = (this.desc.length > 0 ? this.desc : "");
274	
275	$('#' + lookup_div + ' #' + autocomplete_field).autocomplete ({
276		source : function (request, callback)
277		{
278			var data = { 
279				term : request.term, 
280				table : bizobject_table,
281				field : autocomplete_field,
282				columns : cols,
283				order_by : order_by,
284				desc : desc };
285			$.ajax ({
286				url : url,
287				data : data,
288				complete : function (xhr, result)
289					{
290						if (result != 'success') return;
291						var response = xhr.responseText;
292						$('#' + lookup_div + ' #lookup_list').html(response);
293						
294						$("#" + lookup_div + " .lookup_link").click(
295							function (){
296								var id = this.id;
297								$("#" + lookup_div + " #" + control_id).val(id);
298								bizobjectui.callBizObjectSelect(id, lookup_div); return false;
299								});
300					}
301			});
302		}
303	});	
304}
305
306BizObjectUI.prototype.setupSearchButton = function(control_id){
307	
308	var bizobject = this.bizobject;
309	var table = bizobject.table;
310	var bizobjectui = this;
311
312	$("#form_search_" + control_id + " #btn_search_" + control_id).click(
313		function (){
314			var params = "";
315			for(var key in bizobjectui.lookup_fields){
316				params += key + "=" + $("#form_search_" + control_id + " " + "#search_" + key).val() + "&";
317			}			
318			params += "table=" + bizobject.table +
319				"&control_id=" + control_id;
320			$.ajax({
321				type: "POST",
322				url: "./php/dlg_search.php",
323				data: params,
324				success: function(data){
325					$("#search_" + control_id + "_result").html(data);					
326				}
327			});
328		});
329	
330}
331
332BizObjectUI.prototype.setupSearchDlg = function (control_id){
333	var html = "";
334
335	$("#btn_search_" + control_id).click(
336		function (){
337			$("#search_" + control_id + "_dlg").modal();
338		});
339
340
341	//dialog box for searching
342	html += "<div id='search_" + control_id + "_dlg' class='modal fade' role='dialog'>";
343
344	html += "<div class='modal-dialog'>"  +
345				"<div class='modal-content'>" + 
346					"<div class='modal-header'>" +
347						"<button type='button' class='close' data-dismiss='modal'>×</button>" + 
348						"<h4 class='modal-title'>Search Record</h4>
348" + 
349					"</div>" +
350					"<div class='modal-body'>" +
351					"<form id='form_search_" + control_id + "' name='form_search_" + control_id + "'>" +
352					"<fieldset>";
353						
354	//fields that will be used as search keys
355	for(var key in this.lookup_fields){
356		html += "<div class='controls col-lg-4'>" +
357			"<div class='control-group'>" +
358			"<label class='control-label' for='input01'>" + this.lookup_fields[key] + "&nbsp;</label>" +
359			"<div><input type='text' class='form-control input-sm' " +
360				" id='search_" + key + "' name='search_" + key + "' class='col-lg-12'/></div>" +
361			"</div>" +
362			"</div>";
363	}
364
365	html += 		"</fieldset>" +
366					"<div class='col-lg-12 text-right' style='margin-top:1em;margin-bottom:1em'>" +
367					"<input type='button' class='btn btn-flat btn-success' id='btn_search_" + 
368						control_id + "' name='btn_search_" + control_id + "' value='Search'/>" +
369					"</div>" +
370					"<hr/>" +
371					"<div class='col-lg-12'>" + 
372					"<div class='box-body table-responsive'>" + 
373					"<table class='table table-bordered table-hover table-striped table-condensed'>" + 
374					"<thead>";
375	
376	html +=	"<th></th>"; //for id
377	for(var key in this.lookup_fields){
378		html += "<th>" + this.lookup_fields[key] + "</th>";
379	}
380					
381	html += 		"</thead>" +
382					"<tbody id='search_" + control_id + "_result'>" +
383					"</tbody>" + 
384					"</table>" + 
385					"</div>" +
386					"</div>" +
387					"</div>" +
388				"<div class='modal-footer' id='search-result-info'>" +
389				"</div>" +
390				"</form>" +
391				"</div>";	
392	html += "</div>";
393	
394	return html;
395	
396}
397
398//used by setupLookup()
399BizObjectUI.prototype.callBizObjectSelect = function(id, lookup_div){	
400	this.bizobject.data["id"] = id;
401	this.bizobject.select();
402	$('#' + lookup_div + ' #lookup_list').html("");
403	return false;
404}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.