PageRenderTime 27ms CodeModel.GetById 3ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/BMTmobile-master/assets/debugWebService.js

https://gitlab.com/webservers/codeigniter_mobile_dev_server
JavaScript | 466 lines | 224 code | 23 blank | 219 comment | 10 complexity | d12c01a6401824167ae9e16e0cfd2214 MD5 | raw file
  1function XHR_errorHandler(jqXHR, textStatus, errorThrown){
  2	alert(textStatus);	
  3}
  4function _urlEncode(params){
  5	var url = ''; //'?' 
  6	for (key in params){
  7		//if(isString(params[key])) url += key+'="'+params[key]+'"&';	else
  8		url += key+'='+params[key]+'&';
  9	}
 10	url = url.substring(0, url.length-1); //removes the last &
 11	return url;	
 12}
 13
 14
 15	/*function uploadScreenShot(callBack, _data){
 16		Ti.Media.takeScreenshot(function(imageBlob){
 17			Ajax.Send({
 18				method: 'POST',
 19				params : {image: imageBlob.media, data: _data},
 20				cache : false,
 21				timeout : 10000,
 22				url : "uploadJSON/graphicUpload",
 23				onDone : function(j) {//got the json response
 24					if( isFunction(callBack) ) callBack(j, imageBlob);
 25				},
 26				onFail : function(x, eObj) {
 27					eError("networking Error... or Parsing Error???");
 28				},
 29				debug : false
 30			});	
 31		});
 32	}*/
 33/*function jsonPostXHR(_url, _CallBack, _params){
 34	var _p = {};
 35	if( isDefined(_params) ) _p = _params;
 36	//var _Ajax = $.extend({}, Ajax);
 37	Ajax.Send({
 38		method: 'POST',
 39		params : _p,
 40		sync: true,
 41		cache : false,
 42		timeout : 10000,
 43		url : debugWebServiceURL+_url,
 44		onDone : function(j) {//got the json response
 45			eInfo("Response: "+JSON.stringify(j));
 46			if( isFunction(_CallBack) ){					
 47				_CallBack(j);
 48			}
 49		},
 50		onFail : function(x, eObj) {
 51			eError("networking Error... or Parsing Error???");
 52		},
 53		debug : false
 54	});	    
 55}
 56*/
 57function jsonPostXHR(o){
 58	if(isObject(o)){	
 59		var ajx = {
 60	      dataType: 'json',
 61	      url: o.url,
 62	      cache: false,
 63	      type: 'POST',
 64	      async: true,
 65	      error: function(jqXHR, textStatus, errorThrown){
 66	          XHR_errorHandler(jqXHR, textStatus, errorThrown);
 67	      },
 68	      success: function(data, textStatus, jqXHR){
 69	          //console.log("success: "+textStatus+", data: "+data);
 70	          if(isObject(data) && isFunction(o.callBack))	 o.callBack(data);
 71	      }
 72	   };
 73		if(typeof(o.params) != "undefined"){
 74			ajx.data = _urlEncode(o.params);	
 75		}
 76		$.ajax(ajx);
 77	}
 78}
 79
 80var app = {
 81	//These are really here to document upload Parameters
 82	stores: {
 83		_Log = {
 84			session_id: null, //this shouldn't be set as a post parameter
 85			message: null,
 86			data: null
 87		},
 88		_Access = {
 89			ipAddress: null, //$_SERVER['REMOTE_ADDR']; //"192.168.1.1";
 90			userAgent: null, //$_SERVER['HTTP_USER_AGENT']; //"Mozilla";
 91			requestMethod: null //$_SERVER['REQUEST_METHOD']; //"GET";
 92		},
 93		_Pagination = {
 94			start: 0,
 95			total_rows: 0,
 96			per_page: 0
 97			
 98		},
 99		_File = {
100			file_name: ""
101		}
102	},
103	controllers: {
104		base: {}
105	},
106	tests: = function(){		
107		for (key in app.controllers){
108			//loop testing each controller
109			console.log("controller name: "+key);
110			for(_key in app.controllers[key]){
111				//loop through the methods
112				console.log("method name: "+_key+" value: "+app.controllers[key][_key]);
113			}
114		}
115	}
116};
117
118
119//------------------ index.php/upload/ --------------------------------------
120//
121//The Backend Reads the Directory on This
122/*
123	getUploadDetail()				localhost/BMTmobile/index.php/base/getUploadDetail
124	:false
125*/
126app.controllers.base.getGraphicUploadDetailFromFileName = function(_fileName, _CallBack){
127    jsonPostXHR({
128    	url: routerURL+"base/getUploadDetail", 
129    	callBack: _CallBack,
130    	params: {
131    		file_name: _fileName
132    	}
133    });        
134}
135
136app.controllers.base.deleteUploadFileName = function(_fileName, _CallBack){
137    jsonPostXHR({
138    	url: routerURL+"base/delete_upload", 
139    	callBack: _CallBack,
140    	params: {
141    		file_name: _fileName
142    	}
143    });         
144}
145//The Upload generates data in the Database,
146//the fileName is one of the parameters
147/*	getImages()						localhost/BMTmobile/index.php/base/getImages
148	:{"success":true,
149	  "message":"Image Files",
150	  "status":1,
151	  "images":{"path":"\/Users\/user_bss\/Documents\/Titanium_Studio_Workspace\/htdocs\/BMTmobile\/uploads\/graphics",
152	  "total":0,
153	  "children":[]},
154	  "paging":""}
155*/	  
156app.controllers.base.getImages = function(_CallBack){
157    jsonPostXHR({
158    	url: routerURL+"base/getImages", 
159    	callBack: _CallBack,
160    	params: {
161    		start: 0
162    	}
163    });    
164}
165/*
166	getApps()						localhost/BMTmobile/index.php/base/getApps
167	:{"success":true,
168	  "message":"Project Directories",
169	  "status":1,
170	  "apps":{
171		"path":"http:\/\/localhost\/BMTmobile\/uploads\/Mobile_APPs",
172		"dir_name":"webview",
173		"children":[
174			"bootstrap",
175			"remote_load_apps",
176			"titanium302_Blank",
177			"titanium302_FormTest",
178			"webview"],
179		"total":5},
180		"paging":""}
181*/		
182app.controllers.base.getApps = function(_CallBack){
183    jsonPostXHR({
184    	url: routerURL+"base/getApps", 
185    	callBack: _CallBack,
186    	params: {
187    		start: 0
188    	}
189    });
190}
191
192//	getFiles()						localhost/BMTmobile/index.php/base/getFiles
193//	:{"files":null}
194app.controllers.base.getFiles = function(_CallBack){
195    jsonPostXHR({
196    	url: routerURL+"base/getFiles", 
197    	callBack: _CallBack,
198    	params: {
199    		start: 0
200    	}
201    });
202}
203
204/*
205	getArchives()					localhost/BMTmobile/index.php/base/getArchives
206	:{"success":true,
207	  "message":"Archived Files",
208	  "status":1,
209	  "archives":{
210		"path":"\/Users\/user_bss\/Documents\/Titanium_Studio_Workspace\/htdocs\/BMTmobile\/uploads\/archives",
211		"total":0,
212		"children":[]
213	  },
214	  "paging":""
215	}
216*/	
217app.controllers.base.getArchives = function(_CallBack){
218    jsonPostXHR({
219    	url: routerURL+"base/getArchives", 
220    	callBack: _CallBack,
221    	params: {
222    		start: 0
223    	}
224    });
225}
226//------------------ index.php/Log/ --------------------------------------
227//
228//	jsonLogsBySessionsActivity()	localhost/BMTmobile/index.php/base/jsonLogsBySessionsActivity
229//	:error  LogsFromInactiveSession base.php line 564
230app.controllers.base.LogsBySessionsActivity = function(_CallBack){
231    jsonPostXHR({
232    	url: routerURL+"base/jsonLogsBySessionsActivity/", 
233    	callBack: _CallBack
234    });
235}
236/*
237	jsonActiveSessions()			localhost/BMTmobile/index.php/base/jsonActiveSessions
238	:{"Sessions":[{
239		 "id":"86d140113e24abbbc8f7cd88fe061f81",
240		 "ip_address":"127.0.0.1",
241		 "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
242		 "last_activity":"1404357374",
243		 "user_id":"0",
244		 "platform":"Windows 7",
245		 "browser":"Firefox",
246		 "mobile":false}],
247		"success":true,
248		"message":"",
249		"status":1}
250*/		
251app.controllers.base.jsonActiveSessions = function(_CallBack){
252    jsonPostXHR({
253    	url: routerURL+"base/jsonActiveSessions/", 
254    	callBack: _CallBack
255    });	
256}
257
258/*
259	jsonAllSessions()				localhost/BMTmobile/index.php/base/jsonAllSessions
260	:{"Sessions":null,
261	  "success":true,
262	  "message":"",
263	  "status":1}
264	
265	or
266	
267	:{"Sessions":[{
268		 "id":"86d140113e24abbbc8f7cd88fe061f81",
269		 "ip_address":"127.0.0.1",
270		 "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
271		 "last_activity":"1404357374",
272		 "user_id":"0",
273		 "platform":"Windows 7",
274		 "browser":"Firefox",
275		 "mobile":false}],
276		"success":true,
277		"message":"",
278		"status":1}
279*/
280app.controllers.base.jsonAllSessions = function(_CallBack){
281    jsonPostXHR({
282    	url: routerURL+"base/jsonAllSessions/", 
283    	callBack: _CallBack
284    });
285}
286
287/*
288	jsonAccess()					localhost/BMTmobile/index.php/base/jsonAccess
289	:{"Access":[
290		{"id":"86d140113e24abbbc8f7cd88fe061f81",
291		 "ip_address":"127.0.0.1",
292		 "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
293		 "last_activity":"1404357374",
294		 "user_id":"0"}
295		]}
296*/
297app.controllers.base.jsonAccess = function(_CallBack){
298    jsonPostXHR({
299    	url: routerURL+"base/jsonAccess/",
300    	callBack: _CallBack
301    });	
302}
303
304/*
305	yourSession()					localhost/BMTmobile/index.php/base/yourSession
306	:{"session_id":"791bb3716e90e79499614ead1dc7570c",
307	  "ip_address":"127.0.0.1",
308	  "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
309	  "last_activity":1404556261,
310	  "user_data":"",
311	  "validated":false,
312	  "username":"guest",
313	  "type":0,
314	  "user_id":4}
315*/
316app.controllers.base.yourSession = function(_CallBack){
317    jsonPostXHR({
318    	url: routerURL+"base/yourSession/",
319    	callBack: _CallBack
320    });	
321}
322
323//	get_unused_sessions()			localhost/BMTmobile/index.php/base/get_unused_sessions
324//	:""
325app.controllers.base.get_unused_sessions = function(_CallBack){
326    jsonPostXHR({
327    	url: routerURL+"base/get_unused_sessions",
328    	callBack: _CallBack
329    });
330}
331
332
333
334
335/*
336	reset_database()				localhost/BMTmobile/index.php/base/reset_database
337	:{"success":true,
338	 "message":"Successfully cleared Database",
339	 "status":1}
340*/	 
341app.controllers.base.reset_database = function(_CallBack){
342    jsonPostXHR({
343    	url: routerURL+"base/reset_database",
344    	callBack: _CallBack
345    });
346}
347/*	
348	delete_log()					localhost/BMTmobile/index.php/base/delete_log
349	:{"success":false,
350	  "message":"id not set or already deleted",
351	  "status":0}
352*/	  
353app.controllers.base.delete_log = function(_CallBack){
354    jsonPostXHR({
355    	url: routerURL+"base/delete_log",
356		params: {
357		    session_id: o.session_id,
358		    message: o.message,
359		    data: o.data
360		},
361    	callBack: o.callBack
362    });
363}
364/*	  
365	jsonClearLogs()					localhost/BMTmobile/index.php/base/jsonClearLogs	
366	:{"success":false,
367	  "message":"error clearing Logs",
368	  "status":0}
369*/	  
370app.controllers.base.jsonClearLogs = function(_CallBack){
371    jsonPostXHR({
372    	url: routerURL+"base/jsonClearLogs/", 
373    	callBack: _CallBack
374    });	
375}
376
377/*
378	log()							localhost/BMTmobile/index.php/base/log?message=""&session_id=""&data=""	
379	{"success":false,
380	 "message":", message not set!, data not set!",
381	 "status":0}
382
383	:	for multipart form encoded uploads 'filecontent' holds binary data
384			that gets sorted as archive,sound or image.	
385*/
386app.controllers.base.Log = function(o){
387	if(isObject(o)){
388		jsonPostXHR({
389			url: routerURL+"base/log",
390		  params: {
391		    session_id: o.session_id,
392		    message: o.message,
393		    data: o.data
394		  },
395		  callBack: o.callBack
396		});
397	}
398}
399
400
401//	getLogs()						localhost/BMTmobile/index.php/base/getLogs
402//	: {"logs":null}		//return json object with logs for 'session_id' if specified
403app.controllers.base.getLogs = function(o){
404	if(isObject(o)){
405		jsonPostXHR({
406			url: routerURL+"base/getLogs",
407		  params: {
408		    session_id: o.session_id
409		  },
410		  callBack: o.callBack
411		});
412	}
413}
414
415//	isValidated()					localhost/BMTmobile/index.php/base/isValidated
416//	: ""
417app.controllers.base.isValidated = function(_CallBack){
418    jsonPostXHR({
419    	url: routerURL+"base/isValidated", 
420    	callBack: _CallBack
421    });
422}
423/*
424	login()							localhost/BMTmobile/index.php/base/login?name="user"&password="007157"	
425	:{"success":false,
426	  "message":"Incorrect username or password!",
427	  "status":0}
428*/
429app.controllers.base.login = function(){
430    jsonPostXHR({
431    	url: routerURL+"base/isValidated", 
432    	callBack: function(d,x,t){
433			console.log("isValidated: "+d);
434		}
435    });
436}
437
438/*
439	logout()						localhost/BMTmobile/index.php/base/logout
440	: login HTML screen
441*/	  
442app.controllers.base.logout = function(){
443    jsonPostXHR({
444    	url: routerURL+"base/logout", 
445    	callBack: function(d,x,t){
446			console.log("logging out: "+d);
447		}
448    });
449}
450
451/*
452BMTMobile REST interface:
453base.php	: JSON webservices
454
455base.php->base_view.php
456	index()							localhost/BMTmobile/index.php/base_view/
457	nonValidatedContent($data)		localhost/BMTmobile/index.php/base_view/nonValidatedContent
458	login(): 						localhost/BMTmobile/index.php/base_view/login?name="user"&password="007157"	
459	signup()						localhost/BMTmobile/index.php/base_view/signup :generates form
460	upload_form($output = null)		localhost/BMTmobile/index.php/base_view/upload_form
461	gCrudUploads($output = null)	localhost/BMTmobile/index.php/base_view/gCrudUploads
462	gCrudAccess($output = null)		localhost/BMTmobile/index.php/base_view/gCrudAccess
463	gCrudLog($output = null)		localhost/BMTmobile/index.php/base_view/gCrudLog
464	gCrudUser($output = null)		localhost/BMTmobile/index.php/base_view/gCrudUser
465	test()
466*/