PageRenderTime 67ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/assets/controllerData.js

https://gitlab.com/webservers/codeigniter_mobile_dev_server
JavaScript | 1058 lines | 735 code | 46 blank | 277 comment | 87 complexity | 79395e3dae901aedcf58b1d3134ccb07 MD5 | raw file
  1. function XHR_errorHandler(jqXHR, textStatus, errorThrown){
  2. alert(textStatus);
  3. }
  4. function _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. function jsonPostXHR(o){
  15. if(isObject(o)){
  16. var ajx = {
  17. dataType: 'json',
  18. url: o.url,
  19. cache: false,
  20. type: 'POST',
  21. async: true,
  22. error: function(jqXHR, textStatus, errorThrown){
  23. XHR_errorHandler(jqXHR, textStatus, errorThrown);
  24. },
  25. success: function(data, textStatus, jqXHR){
  26. //console.log("success: "+textStatus+", data: "+data);
  27. if(isObject(data) && isFunction(o.callBack)) o.callBack(data);
  28. }
  29. };
  30. if(typeof(o.params) != "undefined"){
  31. ajx.data = _urlEncode(o.params);
  32. }
  33. $.ajax(ajx);
  34. }
  35. }
  36. var app = {
  37. //These are really here to document upload Parameters
  38. stores: {
  39. _Log: {
  40. session_id: null, //this shouldn't be set as a post parameter
  41. message: null,
  42. data: null
  43. },
  44. _Access: {
  45. ipAddress: null, //$_SERVER['REMOTE_ADDR']; //"192.168.1.1";
  46. userAgent: null, //$_SERVER['HTTP_USER_AGENT']; //"Mozilla";
  47. requestMethod: null //$_SERVER['REQUEST_METHOD']; //"GET";
  48. },
  49. _Pagination: {
  50. start: 0,
  51. total_rows: 0,
  52. per_page: 0
  53. },
  54. _File: {
  55. file_name: ""
  56. }
  57. },
  58. controllers: {
  59. base: {}
  60. },
  61. run_tests: function(){
  62. for (key in app.controllers){
  63. //loop testing each controller
  64. console.log("controller name: "+key);
  65. for(_key in app.controllers[key]){
  66. //loop through the methods
  67. console.log("method name: "+_key+" value: "+app.controllers[key]);
  68. //app.controllers[key][_key]();
  69. }
  70. }
  71. },
  72. widget: {}
  73. };
  74. app.controllers.base = {
  75. //------------------ index.php/upload/ --------------------------------------
  76. //
  77. //The Backend Reads the Directory on This
  78. /*
  79. getUploadDetail() localhost/BMTmobile/index.php/base/getUploadDetail
  80. :false
  81. */
  82. getGraphicUploadDetailFromFileName: function(_fileName, _CallBack){
  83. jsonPostXHR({
  84. url: routerURL+"base/getUploadDetail",
  85. callBack: _CallBack,
  86. params: {
  87. file_name: _fileName
  88. }
  89. });
  90. },
  91. deleteUploadFileName: function(_fileName, _CallBack){
  92. jsonPostXHR({
  93. url: routerURL+"base/delete_upload",
  94. callBack: _CallBack,
  95. params: {
  96. file_name: _fileName
  97. }
  98. });
  99. },
  100. //The Upload generates data in the Database,
  101. //the fileName is one of the parameters
  102. /* getImages() localhost/BMTmobile/index.php/base/getImages
  103. :{"success":true,
  104. "message":"Image Files",
  105. "status":1,
  106. "images":{"path":"\/Users\/user_bss\/Documents\/Titanium_Studio_Workspace\/htdocs\/BMTmobile\/uploads\/graphics",
  107. "total":0,
  108. "children":[]},
  109. "paging":""}
  110. */
  111. getImages: function(callBack){
  112. jsonPostXHR({
  113. url: routerURL+"base/getImages",
  114. callBack: function(d){
  115. console.log(d); //d should = binary json
  116. callBack(d);
  117. },
  118. params: {
  119. start: 0
  120. }
  121. });
  122. },
  123. /*
  124. getApps() localhost/BMTmobile/index.php/base/getApps
  125. :{"success":true,
  126. "message":"Project Directories",
  127. "status":1,
  128. "apps":{
  129. "path":"http:\/\/localhost\/BMTmobile\/uploads\/Mobile_APPs",
  130. "dir_name":"webview",
  131. "children":[
  132. "bootstrap",
  133. "remote_load_apps",
  134. "titanium302_Blank",
  135. "titanium302_FormTest",
  136. "webview"],
  137. "total":5},
  138. "paging":""}
  139. */
  140. getApps: function(){
  141. jsonPostXHR({
  142. url: routerURL+"base/getApps",
  143. callBack: function(d){
  144. console.log(d); //d should = binary json
  145. },
  146. params: {
  147. start: 0
  148. }
  149. });
  150. },
  151. // getFiles() localhost/BMTmobile/index.php/base/getFiles
  152. // :{"files":null}
  153. getFiles: function(){
  154. jsonPostXHR({
  155. url: routerURL+"base/getFiles",
  156. callBack: function(d){
  157. console.log(d); //d should = binary json
  158. },
  159. params: {
  160. start: 0
  161. }
  162. });
  163. },
  164. /*
  165. getArchives() localhost/BMTmobile/index.php/base/getArchives
  166. :{"success":true,
  167. "message":"Archived Files",
  168. "status":1,
  169. "archives":{
  170. "path":"\/Users\/user_bss\/Documents\/Titanium_Studio_Workspace\/htdocs\/BMTmobile\/uploads\/archives",
  171. "total":0,
  172. "children":[]
  173. },
  174. "paging":""
  175. }
  176. */
  177. getArchives: function(_CallBack){
  178. jsonPostXHR({
  179. url: routerURL+"base/getArchives",
  180. callBack: function(d){
  181. console.log(d); //d should = binary json
  182. },
  183. params: {
  184. start: 0
  185. }
  186. });
  187. },
  188. //------------------ index.php/Log/ --------------------------------------
  189. //
  190. // jsonLogsBySessionsActivity() localhost/BMTmobile/index.php/base/jsonLogsBySessionsActivity
  191. // :error LogsFromInactiveSession base.php line 564
  192. LogsBySessionsActivity: function(_CallBack){
  193. jsonPostXHR({
  194. url: routerURL+"base/jsonLogsBySessionsActivity/",
  195. callBack: function(d){
  196. console.log(d); //d should = binary json
  197. }
  198. });
  199. },
  200. /*
  201. jsonActiveSessions() localhost/BMTmobile/index.php/base/jsonActiveSessions
  202. :{"Sessions":[{
  203. "id":"86d140113e24abbbc8f7cd88fe061f81",
  204. "ip_address":"127.0.0.1",
  205. "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
  206. "last_activity":"1404357374",
  207. "user_id":"0",
  208. "platform":"Windows 7",
  209. "browser":"Firefox",
  210. "mobile":false}],
  211. "success":true,
  212. "message":"",
  213. "status":1}
  214. */
  215. jsonActiveSessions: function(_CallBack){
  216. jsonPostXHR({
  217. url: routerURL+"base/jsonActiveSessions/",
  218. callBack: _CallBack
  219. });
  220. },
  221. /*
  222. jsonAllSessions() localhost/BMTmobile/index.php/base/jsonAllSessions
  223. :{"Sessions":null,
  224. "success":true,
  225. "message":"",
  226. "status":1}
  227. or
  228. :{"Sessions":[{
  229. "id":"86d140113e24abbbc8f7cd88fe061f81",
  230. "ip_address":"127.0.0.1",
  231. "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
  232. "last_activity":"1404357374",
  233. "user_id":"0",
  234. "platform":"Windows 7",
  235. "browser":"Firefox",
  236. "mobile":false}],
  237. "success":true,
  238. "message":"",
  239. "status":1}
  240. */
  241. jsonAllSessions: function(_CallBack){
  242. jsonPostXHR({
  243. url: routerURL+"base/jsonAllSessions/",
  244. callBack: function(d){
  245. console.log(d); //d should = binary json
  246. }
  247. });
  248. },
  249. /*
  250. jsonAccess() localhost/BMTmobile/index.php/base/jsonAccess
  251. :{"Access":[
  252. {"id":"86d140113e24abbbc8f7cd88fe061f81",
  253. "ip_address":"127.0.0.1",
  254. "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
  255. "last_activity":"1404357374",
  256. "user_id":"0"}
  257. ]}
  258. */
  259. jsonAccess: function(_CallBack){
  260. jsonPostXHR({
  261. url: routerURL+"base/jsonAccess/",
  262. callBack: function(d){
  263. console.log(d); //d should = binary json
  264. }
  265. });
  266. },
  267. /*
  268. yourSession() localhost/BMTmobile/index.php/base/yourSession
  269. :{"session_id":"791bb3716e90e79499614ead1dc7570c",
  270. "ip_address":"127.0.0.1",
  271. "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
  272. "last_activity":1404556261,
  273. "user_data":"",
  274. "validated":false,
  275. "username":"guest",
  276. "type":0,
  277. "user_id":4}
  278. */
  279. yourSession: function(_CallBack){
  280. jsonPostXHR({
  281. url: routerURL+"base/yourSession/",
  282. callBack: function(d){
  283. console.log(d); //d should = binary json
  284. }
  285. });
  286. },
  287. // get_unused_sessions() localhost/BMTmobile/index.php/base/get_unused_sessions
  288. // :""
  289. get_unused_sessions: function(_CallBack){
  290. jsonPostXHR({
  291. url: routerURL+"base/get_unused_sessions",
  292. callBack: function(d){
  293. console.log(d); //d should = binary json
  294. }
  295. });
  296. },
  297. /*
  298. reset_database() localhost/BMTmobile/index.php/base/reset_database
  299. :{"success":true,
  300. "message":"Successfully cleared Database",
  301. "status":1}
  302. */
  303. reset_database: function(){
  304. jsonPostXHR({
  305. url: routerURL+"base/reset_database",
  306. callBack: function(d){
  307. console.log(d); //d should = binary json
  308. }
  309. });
  310. },
  311. /*
  312. delete_log() localhost/BMTmobile/index.php/base/delete_log
  313. :{"success":false,
  314. "message":"id not set or already deleted",
  315. "status":0}
  316. */
  317. delete_log: function(_CallBack){
  318. jsonPostXHR({
  319. url: routerURL+"base/delete_log",
  320. params: {
  321. session_id: o.session_id,
  322. message: o.message,
  323. data: o.data
  324. },
  325. callBack: function(d){
  326. console.log(d); //d should = binary json
  327. }
  328. });
  329. },
  330. /*
  331. jsonClearLogs() localhost/BMTmobile/index.php/base/jsonClearLogs
  332. :{"success":false,
  333. "message":"error clearing Logs",
  334. "status":0}
  335. */
  336. clearLogs: function(_CallBack){
  337. jsonPostXHR({
  338. url: routerURL+"base/jsonClearLogs/",
  339. callBack: function(d){
  340. console.log(d); //d should = binary json
  341. }
  342. });
  343. },
  344. /*
  345. log() localhost/BMTmobile/index.php/base/log?message=""&session_id=""&data=""
  346. {"success":false,
  347. "message":", message not set!, data not set!",
  348. "status":0}
  349. : for multipart form encoded uploads 'filecontent' holds binary data
  350. that gets sorted as archive,sound or image.
  351. */
  352. Log: function(o){
  353. if(isObject(o)){
  354. jsonPostXHR({
  355. url: routerURL+"base/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. // getLogs() localhost/BMTmobile/index.php/base/getLogs
  366. // : {"logs":null} //return json object with logs for 'session_id' if specified
  367. getLogs: function(o){
  368. if(isObject(o)){
  369. jsonPostXHR({
  370. url: routerURL+"base/getLogs",
  371. params: {
  372. session_id: o.session_id
  373. },
  374. callBack: o.callBack
  375. });
  376. }
  377. },
  378. createTestLogs: function(num){
  379. var o = {
  380. str: "hello work",
  381. bool: true,
  382. integer: 1,
  383. floating: 0.5,
  384. array: [0,1,2],
  385. object: {o: "the work"}
  386. };
  387. if(typeof(num) == 'undefined')
  388. num = 10;
  389. for(var i=0;i<num;i++){
  390. this.Log({
  391. message: "test"+i,
  392. data: JSON.stringify(o)
  393. });
  394. }
  395. },
  396. // isValidated() localhost/BMTmobile/index.php/base/isValidated
  397. // : ""
  398. isValidated: function(_CallBack){
  399. jsonPostXHR({
  400. url: routerURL+"base/isValidated",
  401. callBack: _CallBack
  402. });
  403. },
  404. /*
  405. login() localhost/BMTmobile/index.php/base/login?name="user"&password="007157"
  406. :{"success":false,
  407. "message":"Incorrect username or password!",
  408. "status":0}
  409. */
  410. login: function(_CallBack){
  411. jsonPostXHR({
  412. url: routerURL+"base/isValidated",
  413. callBack: function(d,x,t){
  414. console.log("isValidated: "+d);
  415. if(isFunction(_CallBack)) _CallBack();
  416. }
  417. });
  418. },
  419. /*
  420. logout() localhost/BMTmobile/index.php/base/logout
  421. : login HTML screen
  422. */
  423. logout: function(){
  424. jsonPostXHR({
  425. url: routerURL+"base/logout",
  426. callBack: function(d,x,t){
  427. console.log("logging out: "+d);
  428. }
  429. });
  430. }
  431. };
  432. /*
  433. BMTMobile REST interface:
  434. base.php : JSON webservices
  435. base.php->base_view.php
  436. index() localhost/BMTmobile/index.php/base_view/
  437. nonValidatedContent($data) localhost/BMTmobile/index.php/base_view/nonValidatedContent
  438. login(): localhost/BMTmobile/index.php/base_view/login?name="user"&password="007157"
  439. signup() localhost/BMTmobile/index.php/base_view/signup :generates form
  440. upload_form($output = null) localhost/BMTmobile/index.php/base_view/upload_form
  441. gCrudUploads($output = null) localhost/BMTmobile/index.php/base_view/gCrudUploads
  442. gCrudAccess($output = null) localhost/BMTmobile/index.php/base_view/gCrudAccess
  443. gCrudLog($output = null) localhost/BMTmobile/index.php/base_view/gCrudLog
  444. gCrudUser($output = null) localhost/BMTmobile/index.php/base_view/gCrudUser
  445. test()
  446. */
  447. app.widget.newDialog = function(o, _AddedCallback){
  448. /* var o = {
  449. dialogID: "dialog",
  450. dialogTitle: "JsonViewer",
  451. content: "",
  452. url: "",
  453. autoOpen: true,
  454. width: 810,
  455. height: 600
  456. };*/
  457. var parentID = "";
  458. //var parentID = "Content";
  459. //var parentID = "LeftSidebar";
  460. var dialogID = "DefaultID";
  461. var dialogTitle = "Default Title";
  462. var content = "";
  463. var url = "";
  464. var autoOpen = true;
  465. var width = 810;
  466. var height = 600;
  467. var resizable = true;
  468. var contentID = "dialogContent";
  469. if( isObject(o) ){
  470. if( isDefined(o.width) ){
  471. width = o.width;
  472. }
  473. if( isDefined(o.height) ){
  474. height = o.height;
  475. }
  476. if( isString(o.id) ){
  477. dialogID = o.id;
  478. }
  479. if( isString(o.title) ){
  480. dialogTitle = o.title;
  481. }
  482. if( isString(o.url) ){
  483. url = o.url;
  484. }
  485. if( isDefined(o.content) ){
  486. content = o.content;
  487. } else {
  488. //content = '<iframe id="'+contentID+'" src="'+url+'" width="100%" height="90%"></iframe>';
  489. content = '<iframe name="'+dialogID+'" src="'+url+'" width="'+width+'" height="'+height+'"></iframe>';
  490. }
  491. if( isTrue(o.autoOpen)){
  492. autoOpen = true;
  493. }
  494. if( !isTrue(o.resizable)){
  495. resizable = false;
  496. }
  497. }
  498. var dialogHTML = '<div id="'+dialogID+'" title="'+dialogTitle+'">';
  499. dialogHTML += content;
  500. dialogHTML += '</div>';
  501. if( $('#'+dialogID).length > 0 ){
  502. console.log("Updating Existing Log");
  503. $('#'+dialogID).html(content).dialog().show();
  504. }else{
  505. console.log("Adding new Dialog");
  506. $('body').append(dialogHTML);
  507. if( isDefined(o.content) )
  508. $('#'+dialogID).dialog({autoOpen: autoOpen, width: width, height: height, resizable: resizable});
  509. else
  510. $('#'+dialogID).dialog({autoOpen: autoOpen, width: 'auto', height: 'auto', resizable: resizable});
  511. }
  512. //The .load is for images I think but maybe a callback was needed
  513. //I think the operation is blocking until elements are added forthe most part.
  514. //
  515. //I suppose I could wait for open on the iFrame's content?
  516. if(isFunction(_AddedCallback)){
  517. console.log("Dialog Added");
  518. //$('#'+dialogID).load(_AddedCallback);
  519. _AddedCallback();
  520. }
  521. };
  522. app.widget.jsonView = function(_CallBack){
  523. var _content = "";
  524. _content += '<div style="position:absolute;left:10px;background-color: #155e8b; width: 360px;" id="tree"></div>';
  525. _content += '<div style="position:absolute;left:400px" id="jform"></div>';
  526. app.widget.newDialog({
  527. id: "JsonView",
  528. title: "Json Viewer",
  529. content: _content,
  530. autoOpen: true,
  531. width: 810,
  532. height: 600
  533. }, _CallBack);
  534. };
  535. app.widget.jsonViewer = function(_data){
  536. app.widget.jsonView(function(){
  537. var _json = _data;
  538. if(isString(_data)) _json = JSON.parse(_data);
  539. JSONeditor.start('tree','jform',_json,false,false);
  540. });
  541. };
  542. app.widget.jsonEditor = function(_data){
  543. app.widget.jsonView(function(){
  544. var _json = _data;
  545. if(isString(_data)) _json = JSON.parse(_data);
  546. if(!isDefined(_data)) _json = {};
  547. JSONeditor.start('tree','jform',_json,false,true);
  548. });
  549. };
  550. app.widget.addTab = function(o){
  551. var tabHID = "#tabsHeader";
  552. var tabCID = "#tabs";
  553. //o = {title: "AddTab", id: "newTab1", content: "Tab Content"};
  554. var dialogID = "DefaultID";
  555. var dialogTitle = "Default Title";
  556. var content = "";
  557. var width = 810;
  558. var height = 600;
  559. var contentID = "dialogContent";
  560. if( isObject(o) ){
  561. if( isString(o.id) )
  562. dialogID = o.id;
  563. if( isString(o.title) )
  564. dialogTitle = o.title;
  565. if( isDefined(o.content) )
  566. content = o.content;
  567. }
  568. $(tabCID).tabs( "destroy" );
  569. $(tabHID).append('<li><a href="#'+dialogID+'">'+dialogTitle+'</a></li>');
  570. if( isString(o.url) ){
  571. //content = '<div id="'+dialogID+'"><iframe id="'+contentID+'" src="'+o.url+'" width="100%" height="90%"></iframe></div>'; //url must be on this server, cross domain policy
  572. content = '<div id="'+dialogID+'"><iframe id="'+contentID+'" src="'+o.url+'" width="100%" height="'+height+'"></iframe></div>'; //url must be on this server, cross domain policy
  573. }
  574. else
  575. content = '<div id="'+dialogID+'"><div id="'+contentID+'">'+content+'</div></div>';
  576. $(tabCID).append(content);
  577. $(tabCID).tabs();
  578. if(isObject(o) && isFunction(o.AddedCallback)){
  579. console.log("Dialog Added");
  580. //$('#'+dialogID).load(_AddedCallback); //use the load jquery callback.
  581. o.AddedCallback({containerID:dialogID, contentID: contentID});
  582. }
  583. };
  584. app.widget.createJqTabGroup = function(){
  585. if($('#Content').html() != ""){
  586. $('#Content').html('<div id="tabs"><ul id="tabsHeader"></ul><div class="cleared"></div></div>');
  587. $( "#tabs" ).tabs();
  588. $( "#tabs" ).click(function(e){
  589. //console.log(e.target); //<a id="ui-id-3" class="ui-tabs-anchor" href="#ImgView" role="presentation" tabindex="-1">
  590. if(e.target.href == "#ImgView"){
  591. $('#UploadBlock').show();
  592. $('#SessionBlock').hide();
  593. }
  594. if(e.target.href == "#LogView"){
  595. $('#UploadBlock').hide();
  596. $('#SessionBlock').show();
  597. }
  598. //console.log("Tab Clicked: "+e.target+ "type: "+typeof(e.target)); console.log(e.target.indexOf("#")); dump(e.target.toString().indexOf('#'));
  599. /*if(e.target.toString().indexOf('ImgView') != -1){
  600. }
  601. if(e.target.toString().indexOf('LogView') != -1){
  602. }*/
  603. });
  604. $('#UploadBlock').hide();
  605. }
  606. //Hide SideBar Blocks....
  607. //$('#UploadBlock').hide();
  608. //$('#SessionBlock').hide();
  609. /*app.widget.addTab({
  610. id: "LogView",
  611. title: "LogView",
  612. content: "testing..."
  613. //,url: "http://bluemountaintechnologies.com"
  614. });*/
  615. /*app.widget.addTab({
  616. id: "ImgView",
  617. title: "ImgView",
  618. content: "testing..."
  619. //,url: "http://bluemountaintechnologies.com"
  620. });*/
  621. };
  622. //var logs = null;
  623. //var AssetDir = '/BMTmobile/assets/images';
  624. //console.log(path[1]); //index.php
  625. //console.log(path[2]); //controllerName
  626. //console.log(path[2]); //controllerMethod
  627. app.widget.createUserAgentImg = function(platform, browser, isMobile){
  628. var OS_IMG = '';
  629. switch(platform){
  630. case "Unknown Windows OS":
  631. case "Windows 7":
  632. case "Windows":
  633. OS_IMG = 'win.png';
  634. break;
  635. case "Linux":
  636. OS_IMG = 'lin.png';
  637. break;
  638. case "Android":
  639. OS_IMG = 'and.png';
  640. break;
  641. case "Mac OS X":
  642. case "Macintosh":
  643. case "iOS":
  644. OS_IMG = 'mac.png';
  645. break;
  646. }
  647. console.log("platform: "+platform);
  648. var BROWSER_IMG = "";
  649. switch(browser){
  650. case "Android":
  651. BROWSER_IMG = 'and.png';
  652. case "Internet Explorer":
  653. BROWSER_IMG = "int.png";
  654. break;
  655. case "Opera":
  656. BROWSER_IMG = "opr.png";
  657. break;
  658. case "Safari":
  659. BROWSER_IMG = "saf.png";
  660. break;
  661. case "Chrome":
  662. BROWSER_IMG = "chr.png";
  663. break;
  664. case "Konkorer":
  665. BROWSER_IMG = "kon.png";
  666. break;
  667. case "Netscape":
  668. BROWSER_IMG = "net.png";
  669. break;
  670. case "Firefox":
  671. BROWSER_IMG = "fir.png";
  672. break;
  673. }
  674. /*
  675. .User_Agent_Img{
  676. width: 32px;
  677. height: 32px;
  678. background-repeat: no-repeat;
  679. display: block;
  680. position: relative;
  681. }
  682. background-image: url("mac.png");
  683. background-image: url("win.png");
  684. background-image: url("lin.png");
  685. background-image: url("and.png");
  686. background-image: url("kon.png");
  687. background-image: url("net.png");
  688. background-image: url("int.png");
  689. background-image: url("saf.png");
  690. background-image: url("ope.png");
  691. background-image: url("chr.png");
  692. background-image: url("fir.png");
  693. */
  694. //inherits box from User_Agent_Img
  695. return '<img class="User_Agent_Img" src="'+AssetDir+'images/'+BROWSER_IMG+'" style="background-image: url('+AssetDir+'images/'+OS_IMG+')" />';
  696. };
  697. app.widget.createLogTable = function(o){
  698. //$("#LogView").html("");
  699. if(typeof(o) == 'object'){
  700. var tbl = "<h2 class='LogViewTitle'>Log View</h2>";
  701. tbl += "<table class=\"LogViewTable\">";
  702. //tbl += '<tr class="LogViewHeadTable"><td>TimeStamp</td><td>Message</td><td>Data</td><td>id</td></tr>';
  703. tbl += '<tr class="LogViewHeadTable"><td>TimeStamp</td><td>Message</td><td>Data</td></tr>';
  704. for(var i=0;i<o.length;i++){
  705. if(isEven(i)){
  706. tbl += '<tr class="LogViewEvenTable">';
  707. } else {
  708. tbl += '<tr class="LogViewOddTable">';
  709. }
  710. tbl += "<td>"+getDateString(o[i].TimeStamp)+"</td>";
  711. tbl += "<td>"+o[i].Msg+"</td>";
  712. if(o[i].Data == null)
  713. tbl += "<td></td>";
  714. else{
  715. //var s = JSON.stringify(o[i].Data);
  716. tbl += '<td><a href="javascript:void(0)" onclick="viewLogData('+i+')">view</a></td>';
  717. }
  718. //tbl += "<td>"+o[i].id+"</td>";
  719. //tbl += "<td>"+o[i].Session_id+"</td>";
  720. tbl += "</tr>";
  721. }
  722. tbl += "</table>";
  723. //$("#LogView").html(tbl);
  724. return tbl;
  725. }
  726. return false;
  727. };
  728. app.widget.getLogs = function(session_id){
  729. app.controllers.base.getLogs({
  730. session_id: session_id,
  731. callBack: function(d){
  732. //app.widget.createLogTable(d);
  733. console.log("ready to view json");
  734. app.widget.jsonViewer(d);
  735. }
  736. });
  737. };
  738. app.widget.getSessions = function(session_id){
  739. app.controllers.base.jsonActiveSessions(function(data){
  740. console.log(data);
  741. app.widget.createSessionTable(data.Sessions);
  742. });
  743. };
  744. app.widget.createSessionTable = function(Sessions){
  745. $("#ActiveSessions").html("");
  746. var tbl = ""; //"<h2 class='LogViewTitle'>Active Sessions</h2>";
  747. tbl += '<table class="LogViewTable">';
  748. tbl += '<tr class="LogViewHeadTable"><td>Platform</td><td>IP Address</td></tr>';
  749. if( isObject(Sessions) ){
  750. for(var i=0;i<Sessions.length;i++){
  751. //if( (unix_time() - Sessions[i].last_activity) <= 7200 ){ //<7200 = 2hrs
  752. if(isEven(i)){
  753. tbl += '<tr class="LogViewEvenTable">';
  754. } else {
  755. tbl += '<tr class="LogViewOddTable">';
  756. }
  757. tbl += '<td>'+app.widget.createUserAgentImg(Sessions[i].platform, Sessions[i].browser)+'</td><td><a href="javascript:void(0)" onclick="app.widget.getLogs(\''+Sessions[i].id+'\')">'+Sessions[i].ip_address+'</a></td>';
  758. tbl += "</tr>";
  759. //}
  760. }
  761. }
  762. tbl += "</table>";
  763. $("#ActiveSessions").html(tbl);
  764. return false;
  765. };
  766. app.widget.AccessLogView = function(){
  767. app.widget.newDialog({
  768. id: "AccessLogView",
  769. title: "Access Log",
  770. url: routerURL+"base_view/gCrudAccess/",
  771. autoOpen: true,
  772. width: 810,
  773. height: 600
  774. });
  775. };
  776. app.widget.LogView = function(){
  777. app.widget.newDialog({
  778. id: "LogView1",
  779. title: "Logs",
  780. url: routerURL+"base_view/gCrudLog/",
  781. autoOpen: true,
  782. width: 810,
  783. height: 600
  784. });
  785. };
  786. app.widget.UserView = function(){
  787. app.widget.newDialog({
  788. id: "LogView1",
  789. title: "Logs",
  790. url: routerURL+"/base_view/gCrudUser/",
  791. autoOpen: true,
  792. width: 810,
  793. height: 600
  794. });
  795. };
  796. app.widget.viewLogData = function(_i){
  797. app.widget.jsonView(function(){
  798. console.log("Dialog Callback!");
  799. var _json = JSON.parse(logs[_i].Data);
  800. JSONeditor.start('tree','jform',_json,false,false);
  801. });
  802. };
  803. app.widget.createLogTableWithFileLogs = function(){
  804. //$("#LogView").html("");
  805. if(typeof(logs) == 'object'){
  806. var tbl = "<h2 class='LogViewTitle'>Log View</h2>";
  807. tbl += "<table class=\"LogViewTable\">";
  808. //tbl += '<tr class="LogViewHeadTable"><td>TimeStamp</td><td>Message</td><td>Data</td><td>id</td></tr>';
  809. tbl += '<tr class="LogViewHeadTable"><td>TimeStamp</td><td>Message</td><td>Data</td></tr>';
  810. for(var i=0;i<logs.length;i++){
  811. if(isEven(i)){
  812. tbl += '<tr class="LogViewEvenTable">';
  813. } else {
  814. tbl += '<tr class="LogViewOddTable">';
  815. }
  816. tbl += "<td>"+getDateString(logs[i].TimeStamp)+"</td>";
  817. tbl += "<td>"+logs[i].Message+"</td>";
  818. if(logs[i].Data == null)
  819. tbl += "<td></td>";
  820. else{
  821. //var s = JSON.stringify(logs[i].Data);
  822. tbl += '<td><a href="javascript:void(0)" onclick="app.widget.viewLogData('+i+')">view</a></td>';
  823. }
  824. //tbl += "<td>"+logs[i].id+"</td>";
  825. //tbl += "<td>"+logs[i].Session_id+"</td>";
  826. tbl += "</tr>";
  827. }
  828. tbl += "</table>";
  829. //$("#LogView").html(tbl);
  830. return tbl;
  831. }
  832. return false;
  833. };
  834. var graphics = null;
  835. function updateZoomImage(index){
  836. $('#zoom_image').attr('src', graphics.images[index].url);
  837. $('#zoom_image').click(function(){ getGraphicUploadDetail(index); });
  838. }
  839. function getGraphicUploadDetail(_index){
  840. var fName = graphics.images[_index].url.slice(graphics.images[_index].url.lastIndexOf('/')+1);
  841. app.controllers.base.getGraphicUploadDetailFromFileName(fName, jsonViewer);
  842. }
  843. app.widget.createGraphicsView = function(){
  844. function addImage(index){
  845. try{
  846. return '<img class="tn" src="'+graphics.images[index].thumb_url+'" onclick="updateZoomImage('+index+')"/>';
  847. } catch(e){
  848. console.error("Error processing index: "+index);
  849. //console.error("Error: "+e);
  850. }
  851. }
  852. var zoom_image = '<img id="zoom_image" width="480" height="360" src="'+graphics.images[0].url+'"/>';
  853. $('#zoom_box').html(zoom_image);
  854. $('#zoom_image').click(function(e){
  855. console.log(e.target.src); //echo src property of image
  856. //getGraphicUploadDetail(0);
  857. });
  858. var img = '';
  859. for(var i=0;i<graphics.images.length;i++){
  860. img += addImage(i);
  861. }
  862. $('#tn_box').html(img);
  863. };
  864. //TODO need to clear the view if data == null
  865. app.widget.getGraphics = function(){
  866. app.controllers.base.getImages(app.widget.createGraphicsView);
  867. };
  868. function getFileNameFromIndex(_index){
  869. return graphics.images[_index].url.slice(graphics.images[_index].url.lastIndexOf('/')+1);
  870. }
  871. function getFileNameFromImgSrc(img_src){
  872. return img_src.slice(img_src.lastIndexOf('/')+1);
  873. }
  874. app.controllers.base.DelImage = function(index){
  875. console.log("Deleteing File in Index: "+index);
  876. app.controllers.base.deleteUploadFileName(getFileNameFromIndex(index), function(e){
  877. //console.log("Callback Data:"+e);
  878. //should remove the image from the zoom view, and load the next one in the array
  879. //and update the info view to match the image
  880. //for now not very efficiant but it'll work on a fast connection
  881. app.widget.getGraphics();
  882. });
  883. };
  884. app.widget.update_graphicDetails = function(index){
  885. function getLabel(k, v){
  886. return '<label>'+k+': '+v+'</label><br/>';
  887. }
  888. //'.ImgInfoBox' class name of details box
  889. //var s = '';
  890. var s = '<img src="'+AssetDir+'images/del.png" alt="Delete Image" onclick="DelImage('+index+')"/>';
  891. var o = graphics.images[index];
  892. for( key in o ){
  893. s += getLabel(key, o[key]);
  894. }
  895. $('#info_box').html(s);
  896. $('#zoom_image').attr('src', graphics.images[index].url);
  897. };
  898. app.controllers.base.getMobileApps = function(_CallBack){
  899. $.ajax({
  900. url: routerURL+"base/getApps",
  901. type: "POST",
  902. dataType: 'json',
  903. error: function(jqXHR, textStatus, errorThrown){
  904. XHR_errorHandler(jqXHR, textStatus, errorThrown);
  905. },
  906. success: function(data, textStatus, jqXHR){
  907. //console.log("success: "+textStatus+", data: "+data);
  908. if( data.success && isFunction(_CallBack) ) _CallBack(data);
  909. }
  910. });
  911. };
  912. //titanium Iframe execution code
  913. function getIframeVar(_windowName, _id){
  914. var id = 'tiIpad'; if(typeof(id) != 'undefined') id = _id;
  915. if(typeof(_windowName) != 'undfined')
  916. return document.getElementById(id).children[id].contentWindow[_windowName];
  917. return false;
  918. }
  919. function evalIframe(_code, _id){
  920. var id = 'tiIpad'; if(typeof(id) != 'undefined') id = _id;
  921. return document.getElementById(_id).children[_id].contentWindow.eval(_code);
  922. }
  923. app.widget.tiMobileFrame = function (_url, _title, _id, type){
  924. var id = "tiAndroid";
  925. var width = 480;
  926. var height = 800;
  927. if(typeof(type) == "string"){
  928. if(type == "ipad"){
  929. id = 'tiIpad';
  930. width = 768;
  931. height = 1024;
  932. }
  933. if(type == "iphone"){
  934. id = 'tiIphone';
  935. width = 320;
  936. height = 480;
  937. }
  938. }
  939. if(typeof(id) != 'undefined')
  940. id = _id;
  941. if(typeof(_url) == 'string'){
  942. app.widget.newDialog({
  943. id: _id,
  944. title: _title,
  945. url: _url,
  946. autoOpen: true,
  947. width: width,
  948. height: height,
  949. resizable: false
  950. });
  951. console.log("Adding TiDialog");
  952. console.log('to run code call evalIFrame("'+_id+'", "code");');
  953. }
  954. }
  955. var appData = null;
  956. function appLinkClicked(e){
  957. try{
  958. console.log("click event data: "+e.id); //click event data: javascript:void(0);
  959. var id = e.id;
  960. if(typeof(id) == 'string'&& typeof(appData) == 'object'){
  961. var patt = /[0-9][0-9]*/g;
  962. var _offset = patt.exec(id);
  963. var _url = appData.apps.path + "/" + appData.apps.children[_offset];
  964. var _title = appData.apps.children[_offset];
  965. var _id = 'Ti' + id;
  966. console.log("url: "+_url);
  967. app.widget.tiMobileFrame(_url, _title, _id, "iphone");
  968. }
  969. } catch(e){
  970. console.error("Error: "+e);
  971. }
  972. }
  973. app.widget.createMobileAppView = function(){
  974. app.controllers.base.getMobileApps(function(data){
  975. appData = data;
  976. console.log("message: "+appData.message);
  977. try{
  978. $('#TiDemos').html('');
  979. if(appData.apps.total != appData.apps.children.length){
  980. console.log("Server error data.total != children.length");
  981. return false;
  982. } else{
  983. //if( typeof(appData.apps.paging) != '') { // }
  984. var s = '';
  985. for(var $i=0;$i<appData.apps.total; $i++){
  986. var click_label = appData.apps.children[$i];
  987. console.log(click_label);
  988. s += '<a href="JavaScript:void(0);" onclick="appLinkClicked(this);" id="appDir'+$i+'" >'+click_label+'</a></br>';
  989. }
  990. console.log("TiDemos: "+s);
  991. $('#TiDemos').html(s);
  992. }
  993. } catch(e){
  994. console.error("Error: "+e);
  995. }
  996. });
  997. };
  998. app.start = function(){
  999. app.widget.getSessions();
  1000. app.widget.createMobileAppView();
  1001. };
  1002. $(function(){
  1003. //JSONeditor.treeBuilder.path = AssetDir+'JSONeditor2/treeBuilderImages/'; //tried to override but it doesn't seem to work???
  1004. //$('#UploadSubit').button();
  1005. //$('#AddFiles').button();
  1006. //$('#UploadBlock').show();
  1007. app.start();
  1008. });