PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/BMTmobile-master/assets/controllerData.js

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