/assets/controllerData.js
JavaScript | 1058 lines | 735 code | 46 blank | 277 comment | 87 complexity | 79395e3dae901aedcf58b1d3134ccb07 MD5 | raw file
- function XHR_errorHandler(jqXHR, textStatus, errorThrown){
- alert(textStatus);
- }
- function _urlEncode(params){
- var url = ''; //'?'
- for (key in params){
- //if(isString(params[key])) url += key+'="'+params[key]+'"&'; else
- url += key+'='+params[key]+'&';
- }
- url = url.substring(0, url.length-1); //removes the last &
- return url;
- }
- //
- function jsonPostXHR(o){
- if(isObject(o)){
- var ajx = {
- dataType: 'json',
- url: o.url,
- cache: false,
- type: 'POST',
- async: true,
- error: function(jqXHR, textStatus, errorThrown){
- XHR_errorHandler(jqXHR, textStatus, errorThrown);
- },
- success: function(data, textStatus, jqXHR){
- //console.log("success: "+textStatus+", data: "+data);
- if(isObject(data) && isFunction(o.callBack)) o.callBack(data);
- }
- };
- if(typeof(o.params) != "undefined"){
- ajx.data = _urlEncode(o.params);
- }
- $.ajax(ajx);
- }
- }
- var app = {
- //These are really here to document upload Parameters
- stores: {
- _Log: {
- session_id: null, //this shouldn't be set as a post parameter
- message: null,
- data: null
- },
- _Access: {
- ipAddress: null, //$_SERVER['REMOTE_ADDR']; //"192.168.1.1";
- userAgent: null, //$_SERVER['HTTP_USER_AGENT']; //"Mozilla";
- requestMethod: null //$_SERVER['REQUEST_METHOD']; //"GET";
- },
- _Pagination: {
- start: 0,
- total_rows: 0,
- per_page: 0
-
- },
- _File: {
- file_name: ""
- }
- },
- controllers: {
- base: {}
- },
- run_tests: function(){
- for (key in app.controllers){
- //loop testing each controller
- console.log("controller name: "+key);
- for(_key in app.controllers[key]){
- //loop through the methods
- console.log("method name: "+_key+" value: "+app.controllers[key]);
- //app.controllers[key][_key]();
- }
- }
- },
- widget: {}
- };
- app.controllers.base = {
- //------------------ index.php/upload/ --------------------------------------
- //
- //The Backend Reads the Directory on This
- /*
- getUploadDetail() localhost/BMTmobile/index.php/base/getUploadDetail
- :false
- */
- getGraphicUploadDetailFromFileName: function(_fileName, _CallBack){
- jsonPostXHR({
- url: routerURL+"base/getUploadDetail",
- callBack: _CallBack,
- params: {
- file_name: _fileName
- }
- });
- },
- deleteUploadFileName: function(_fileName, _CallBack){
- jsonPostXHR({
- url: routerURL+"base/delete_upload",
- callBack: _CallBack,
- params: {
- file_name: _fileName
- }
- });
- },
- //The Upload generates data in the Database,
- //the fileName is one of the parameters
- /* getImages() localhost/BMTmobile/index.php/base/getImages
- :{"success":true,
- "message":"Image Files",
- "status":1,
- "images":{"path":"\/Users\/user_bss\/Documents\/Titanium_Studio_Workspace\/htdocs\/BMTmobile\/uploads\/graphics",
- "total":0,
- "children":[]},
- "paging":""}
- */
- getImages: function(callBack){
- jsonPostXHR({
- url: routerURL+"base/getImages",
- callBack: function(d){
- console.log(d); //d should = binary json
- callBack(d);
- },
- params: {
- start: 0
- }
- });
- },
- /*
- getApps() localhost/BMTmobile/index.php/base/getApps
- :{"success":true,
- "message":"Project Directories",
- "status":1,
- "apps":{
- "path":"http:\/\/localhost\/BMTmobile\/uploads\/Mobile_APPs",
- "dir_name":"webview",
- "children":[
- "bootstrap",
- "remote_load_apps",
- "titanium302_Blank",
- "titanium302_FormTest",
- "webview"],
- "total":5},
- "paging":""}
- */
- getApps: function(){
- jsonPostXHR({
- url: routerURL+"base/getApps",
- callBack: function(d){
- console.log(d); //d should = binary json
- },
- params: {
- start: 0
- }
- });
- },
- // getFiles() localhost/BMTmobile/index.php/base/getFiles
- // :{"files":null}
- getFiles: function(){
- jsonPostXHR({
- url: routerURL+"base/getFiles",
- callBack: function(d){
- console.log(d); //d should = binary json
- },
- params: {
- start: 0
- }
- });
- },
- /*
- getArchives() localhost/BMTmobile/index.php/base/getArchives
- :{"success":true,
- "message":"Archived Files",
- "status":1,
- "archives":{
- "path":"\/Users\/user_bss\/Documents\/Titanium_Studio_Workspace\/htdocs\/BMTmobile\/uploads\/archives",
- "total":0,
- "children":[]
- },
- "paging":""
- }
- */
- getArchives: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/getArchives",
- callBack: function(d){
- console.log(d); //d should = binary json
- },
- params: {
- start: 0
- }
- });
- },
- //------------------ index.php/Log/ --------------------------------------
- //
- // jsonLogsBySessionsActivity() localhost/BMTmobile/index.php/base/jsonLogsBySessionsActivity
- // :error LogsFromInactiveSession base.php line 564
- LogsBySessionsActivity: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/jsonLogsBySessionsActivity/",
- callBack: function(d){
- console.log(d); //d should = binary json
- }
- });
- },
- /*
- jsonActiveSessions() localhost/BMTmobile/index.php/base/jsonActiveSessions
- :{"Sessions":[{
- "id":"86d140113e24abbbc8f7cd88fe061f81",
- "ip_address":"127.0.0.1",
- "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
- "last_activity":"1404357374",
- "user_id":"0",
- "platform":"Windows 7",
- "browser":"Firefox",
- "mobile":false}],
- "success":true,
- "message":"",
- "status":1}
- */
- jsonActiveSessions: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/jsonActiveSessions/",
- callBack: _CallBack
- });
- },
- /*
- jsonAllSessions() localhost/BMTmobile/index.php/base/jsonAllSessions
- :{"Sessions":null,
- "success":true,
- "message":"",
- "status":1}
-
- or
-
- :{"Sessions":[{
- "id":"86d140113e24abbbc8f7cd88fe061f81",
- "ip_address":"127.0.0.1",
- "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
- "last_activity":"1404357374",
- "user_id":"0",
- "platform":"Windows 7",
- "browser":"Firefox",
- "mobile":false}],
- "success":true,
- "message":"",
- "status":1}
- */
- jsonAllSessions: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/jsonAllSessions/",
- callBack: function(d){
- console.log(d); //d should = binary json
- }
- });
- },
- /*
- jsonAccess() localhost/BMTmobile/index.php/base/jsonAccess
- :{"Access":[
- {"id":"86d140113e24abbbc8f7cd88fe061f81",
- "ip_address":"127.0.0.1",
- "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
- "last_activity":"1404357374",
- "user_id":"0"}
- ]}
- */
- jsonAccess: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/jsonAccess/",
- callBack: function(d){
- console.log(d); //d should = binary json
- }
- });
- },
- /*
- yourSession() localhost/BMTmobile/index.php/base/yourSession
- :{"session_id":"791bb3716e90e79499614ead1dc7570c",
- "ip_address":"127.0.0.1",
- "user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko\/20100101 Firefox\/30.0",
- "last_activity":1404556261,
- "user_data":"",
- "validated":false,
- "username":"guest",
- "type":0,
- "user_id":4}
- */
- yourSession: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/yourSession/",
- callBack: function(d){
- console.log(d); //d should = binary json
- }
- });
- },
- // get_unused_sessions() localhost/BMTmobile/index.php/base/get_unused_sessions
- // :""
- get_unused_sessions: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/get_unused_sessions",
- callBack: function(d){
- console.log(d); //d should = binary json
- }
- });
- },
- /*
- reset_database() localhost/BMTmobile/index.php/base/reset_database
- :{"success":true,
- "message":"Successfully cleared Database",
- "status":1}
- */
- reset_database: function(){
- jsonPostXHR({
- url: routerURL+"base/reset_database",
- callBack: function(d){
- console.log(d); //d should = binary json
- }
- });
- },
- /*
- delete_log() localhost/BMTmobile/index.php/base/delete_log
- :{"success":false,
- "message":"id not set or already deleted",
- "status":0}
- */
- delete_log: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/delete_log",
- params: {
- session_id: o.session_id,
- message: o.message,
- data: o.data
- },
- callBack: function(d){
- console.log(d); //d should = binary json
- }
- });
- },
-
- /*
- jsonClearLogs() localhost/BMTmobile/index.php/base/jsonClearLogs
- :{"success":false,
- "message":"error clearing Logs",
- "status":0}
- */
- clearLogs: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/jsonClearLogs/",
- callBack: function(d){
- console.log(d); //d should = binary json
- }
- });
- },
- /*
- log() localhost/BMTmobile/index.php/base/log?message=""&session_id=""&data=""
- {"success":false,
- "message":", message not set!, data not set!",
- "status":0}
- : for multipart form encoded uploads 'filecontent' holds binary data
- that gets sorted as archive,sound or image.
- */
- Log: function(o){
- if(isObject(o)){
- jsonPostXHR({
- url: routerURL+"base/log",
- params: {
- session_id: o.session_id,
- message: o.message,
- data: o.data
- },
- callBack: o.callBack
- });
- }
- },
- // getLogs() localhost/BMTmobile/index.php/base/getLogs
- // : {"logs":null} //return json object with logs for 'session_id' if specified
- getLogs: function(o){
- if(isObject(o)){
- jsonPostXHR({
- url: routerURL+"base/getLogs",
- params: {
- session_id: o.session_id
- },
- callBack: o.callBack
- });
- }
- },
- createTestLogs: function(num){
- var o = {
- str: "hello work",
- bool: true,
- integer: 1,
- floating: 0.5,
- array: [0,1,2],
- object: {o: "the work"}
- };
- if(typeof(num) == 'undefined')
- num = 10;
- for(var i=0;i<num;i++){
- this.Log({
- message: "test"+i,
- data: JSON.stringify(o)
- });
- }
- },
- // isValidated() localhost/BMTmobile/index.php/base/isValidated
- // : ""
- isValidated: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/isValidated",
- callBack: _CallBack
- });
- },
- /*
- login() localhost/BMTmobile/index.php/base/login?name="user"&password="007157"
- :{"success":false,
- "message":"Incorrect username or password!",
- "status":0}
- */
- login: function(_CallBack){
- jsonPostXHR({
- url: routerURL+"base/isValidated",
- callBack: function(d,x,t){
- console.log("isValidated: "+d);
- if(isFunction(_CallBack)) _CallBack();
- }
- });
- },
- /*
- logout() localhost/BMTmobile/index.php/base/logout
- : login HTML screen
- */
- logout: function(){
- jsonPostXHR({
- url: routerURL+"base/logout",
- callBack: function(d,x,t){
- console.log("logging out: "+d);
- }
- });
- }
- };
- /*
- BMTMobile REST interface:
- base.php : JSON webservices
- base.php->base_view.php
- index() localhost/BMTmobile/index.php/base_view/
- nonValidatedContent($data) localhost/BMTmobile/index.php/base_view/nonValidatedContent
- login(): localhost/BMTmobile/index.php/base_view/login?name="user"&password="007157"
- signup() localhost/BMTmobile/index.php/base_view/signup :generates form
- upload_form($output = null) localhost/BMTmobile/index.php/base_view/upload_form
- gCrudUploads($output = null) localhost/BMTmobile/index.php/base_view/gCrudUploads
- gCrudAccess($output = null) localhost/BMTmobile/index.php/base_view/gCrudAccess
- gCrudLog($output = null) localhost/BMTmobile/index.php/base_view/gCrudLog
- gCrudUser($output = null) localhost/BMTmobile/index.php/base_view/gCrudUser
- test()
- */
- app.widget.newDialog = function(o, _AddedCallback){
- /* var o = {
- dialogID: "dialog",
- dialogTitle: "JsonViewer",
- content: "",
- url: "",
- autoOpen: true,
- width: 810,
- height: 600
- };*/
- var parentID = "";
- //var parentID = "Content";
- //var parentID = "LeftSidebar";
- var dialogID = "DefaultID";
- var dialogTitle = "Default Title";
- var content = "";
- var url = "";
- var autoOpen = true;
- var width = 810;
- var height = 600;
- var resizable = true;
- var contentID = "dialogContent";
- if( isObject(o) ){
- if( isDefined(o.width) ){
- width = o.width;
- }
- if( isDefined(o.height) ){
- height = o.height;
- }
- if( isString(o.id) ){
- dialogID = o.id;
- }
- if( isString(o.title) ){
- dialogTitle = o.title;
- }
- if( isString(o.url) ){
- url = o.url;
- }
- if( isDefined(o.content) ){
- content = o.content;
- } else {
- //content = '<iframe id="'+contentID+'" src="'+url+'" width="100%" height="90%"></iframe>';
- content = '<iframe name="'+dialogID+'" src="'+url+'" width="'+width+'" height="'+height+'"></iframe>';
- }
- if( isTrue(o.autoOpen)){
- autoOpen = true;
- }
- if( !isTrue(o.resizable)){
- resizable = false;
- }
- }
- var dialogHTML = '<div id="'+dialogID+'" title="'+dialogTitle+'">';
- dialogHTML += content;
- dialogHTML += '</div>';
- if( $('#'+dialogID).length > 0 ){
- console.log("Updating Existing Log");
- $('#'+dialogID).html(content).dialog().show();
- }else{
- console.log("Adding new Dialog");
- $('body').append(dialogHTML);
- if( isDefined(o.content) )
- $('#'+dialogID).dialog({autoOpen: autoOpen, width: width, height: height, resizable: resizable});
- else
- $('#'+dialogID).dialog({autoOpen: autoOpen, width: 'auto', height: 'auto', resizable: resizable});
- }
- //The .load is for images I think but maybe a callback was needed
- //I think the operation is blocking until elements are added forthe most part.
- //
- //I suppose I could wait for open on the iFrame's content?
- if(isFunction(_AddedCallback)){
- console.log("Dialog Added");
- //$('#'+dialogID).load(_AddedCallback);
- _AddedCallback();
- }
- };
- app.widget.jsonView = function(_CallBack){
- var _content = "";
- _content += '<div style="position:absolute;left:10px;background-color: #155e8b; width: 360px;" id="tree"></div>';
- _content += '<div style="position:absolute;left:400px" id="jform"></div>';
- app.widget.newDialog({
- id: "JsonView",
- title: "Json Viewer",
- content: _content,
- autoOpen: true,
- width: 810,
- height: 600
- }, _CallBack);
- };
- app.widget.jsonViewer = function(_data){
- app.widget.jsonView(function(){
- var _json = _data;
- if(isString(_data)) _json = JSON.parse(_data);
- JSONeditor.start('tree','jform',_json,false,false);
- });
- };
- app.widget.jsonEditor = function(_data){
- app.widget.jsonView(function(){
- var _json = _data;
- if(isString(_data)) _json = JSON.parse(_data);
- if(!isDefined(_data)) _json = {};
- JSONeditor.start('tree','jform',_json,false,true);
- });
- };
- app.widget.addTab = function(o){
- var tabHID = "#tabsHeader";
- var tabCID = "#tabs";
-
- //o = {title: "AddTab", id: "newTab1", content: "Tab Content"};
- var dialogID = "DefaultID";
- var dialogTitle = "Default Title";
- var content = "";
- var width = 810;
- var height = 600;
- var contentID = "dialogContent";
- if( isObject(o) ){
- if( isString(o.id) )
- dialogID = o.id;
- if( isString(o.title) )
- dialogTitle = o.title;
- if( isDefined(o.content) )
- content = o.content;
- }
- $(tabCID).tabs( "destroy" );
- $(tabHID).append('<li><a href="#'+dialogID+'">'+dialogTitle+'</a></li>');
- if( isString(o.url) ){
- //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
- 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
- }
- else
- content = '<div id="'+dialogID+'"><div id="'+contentID+'">'+content+'</div></div>';
- $(tabCID).append(content);
- $(tabCID).tabs();
- if(isObject(o) && isFunction(o.AddedCallback)){
- console.log("Dialog Added");
- //$('#'+dialogID).load(_AddedCallback); //use the load jquery callback.
- o.AddedCallback({containerID:dialogID, contentID: contentID});
- }
- };
- app.widget.createJqTabGroup = function(){
- if($('#Content').html() != ""){
- $('#Content').html('<div id="tabs"><ul id="tabsHeader"></ul><div class="cleared"></div></div>');
- $( "#tabs" ).tabs();
- $( "#tabs" ).click(function(e){
- //console.log(e.target); //<a id="ui-id-3" class="ui-tabs-anchor" href="#ImgView" role="presentation" tabindex="-1">
- if(e.target.href == "#ImgView"){
- $('#UploadBlock').show();
- $('#SessionBlock').hide();
- }
- if(e.target.href == "#LogView"){
- $('#UploadBlock').hide();
- $('#SessionBlock').show();
- }
- //console.log("Tab Clicked: "+e.target+ "type: "+typeof(e.target)); console.log(e.target.indexOf("#")); dump(e.target.toString().indexOf('#'));
- /*if(e.target.toString().indexOf('ImgView') != -1){
- }
- if(e.target.toString().indexOf('LogView') != -1){
- }*/
- });
- $('#UploadBlock').hide();
- }
- //Hide SideBar Blocks....
- //$('#UploadBlock').hide();
- //$('#SessionBlock').hide();
-
- /*app.widget.addTab({
- id: "LogView",
- title: "LogView",
- content: "testing..."
- //,url: "http://bluemountaintechnologies.com"
- });*/
- /*app.widget.addTab({
- id: "ImgView",
- title: "ImgView",
- content: "testing..."
- //,url: "http://bluemountaintechnologies.com"
- });*/
- };
- //var logs = null;
- //var AssetDir = '/BMTmobile/assets/images';
- //console.log(path[1]); //index.php
- //console.log(path[2]); //controllerName
- //console.log(path[2]); //controllerMethod
- app.widget.createUserAgentImg = function(platform, browser, isMobile){
- var OS_IMG = '';
- switch(platform){
- case "Unknown Windows OS":
- case "Windows 7":
- case "Windows":
- OS_IMG = 'win.png';
- break;
- case "Linux":
- OS_IMG = 'lin.png';
- break;
- case "Android":
- OS_IMG = 'and.png';
- break;
- case "Mac OS X":
- case "Macintosh":
- case "iOS":
- OS_IMG = 'mac.png';
- break;
- }
- console.log("platform: "+platform);
- var BROWSER_IMG = "";
- switch(browser){
- case "Android":
- BROWSER_IMG = 'and.png';
- case "Internet Explorer":
- BROWSER_IMG = "int.png";
- break;
- case "Opera":
- BROWSER_IMG = "opr.png";
- break;
- case "Safari":
- BROWSER_IMG = "saf.png";
- break;
- case "Chrome":
- BROWSER_IMG = "chr.png";
- break;
- case "Konkorer":
- BROWSER_IMG = "kon.png";
- break;
- case "Netscape":
- BROWSER_IMG = "net.png";
- break;
- case "Firefox":
- BROWSER_IMG = "fir.png";
- break;
- }
-
- /*
- .User_Agent_Img{
- width: 32px;
- height: 32px;
- background-repeat: no-repeat;
- display: block;
- position: relative;
- }
- background-image: url("mac.png");
- background-image: url("win.png");
- background-image: url("lin.png");
- background-image: url("and.png");
- background-image: url("kon.png");
- background-image: url("net.png");
- background-image: url("int.png");
- background-image: url("saf.png");
- background-image: url("ope.png");
- background-image: url("chr.png");
- background-image: url("fir.png");
- */
- //inherits box from User_Agent_Img
- return '<img class="User_Agent_Img" src="'+AssetDir+'images/'+BROWSER_IMG+'" style="background-image: url('+AssetDir+'images/'+OS_IMG+')" />';
- };
- app.widget.createLogTable = function(o){
- //$("#LogView").html("");
- if(typeof(o) == 'object'){
- var tbl = "<h2 class='LogViewTitle'>Log View</h2>";
- tbl += "<table class=\"LogViewTable\">";
- //tbl += '<tr class="LogViewHeadTable"><td>TimeStamp</td><td>Message</td><td>Data</td><td>id</td></tr>';
- tbl += '<tr class="LogViewHeadTable"><td>TimeStamp</td><td>Message</td><td>Data</td></tr>';
- for(var i=0;i<o.length;i++){
- if(isEven(i)){
- tbl += '<tr class="LogViewEvenTable">';
- } else {
- tbl += '<tr class="LogViewOddTable">';
- }
- tbl += "<td>"+getDateString(o[i].TimeStamp)+"</td>";
- tbl += "<td>"+o[i].Msg+"</td>";
- if(o[i].Data == null)
- tbl += "<td></td>";
- else{
- //var s = JSON.stringify(o[i].Data);
- tbl += '<td><a href="javascript:void(0)" onclick="viewLogData('+i+')">view</a></td>';
- }
- //tbl += "<td>"+o[i].id+"</td>";
- //tbl += "<td>"+o[i].Session_id+"</td>";
- tbl += "</tr>";
- }
- tbl += "</table>";
- //$("#LogView").html(tbl);
- return tbl;
- }
- return false;
- };
- app.widget.getLogs = function(session_id){
- app.controllers.base.getLogs({
- session_id: session_id,
- callBack: function(d){
- //app.widget.createLogTable(d);
- console.log("ready to view json");
- app.widget.jsonViewer(d);
- }
- });
- };
- app.widget.getSessions = function(session_id){
- app.controllers.base.jsonActiveSessions(function(data){
- console.log(data);
- app.widget.createSessionTable(data.Sessions);
- });
- };
- app.widget.createSessionTable = function(Sessions){
- $("#ActiveSessions").html("");
- var tbl = ""; //"<h2 class='LogViewTitle'>Active Sessions</h2>";
- tbl += '<table class="LogViewTable">';
- tbl += '<tr class="LogViewHeadTable"><td>Platform</td><td>IP Address</td></tr>';
- if( isObject(Sessions) ){
- for(var i=0;i<Sessions.length;i++){
- //if( (unix_time() - Sessions[i].last_activity) <= 7200 ){ //<7200 = 2hrs
- if(isEven(i)){
- tbl += '<tr class="LogViewEvenTable">';
- } else {
- tbl += '<tr class="LogViewOddTable">';
- }
- 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>';
- tbl += "</tr>";
- //}
- }
- }
- tbl += "</table>";
- $("#ActiveSessions").html(tbl);
- return false;
- };
- app.widget.AccessLogView = function(){
- app.widget.newDialog({
- id: "AccessLogView",
- title: "Access Log",
- url: routerURL+"base_view/gCrudAccess/",
- autoOpen: true,
- width: 810,
- height: 600
- });
- };
- app.widget.LogView = function(){
- app.widget.newDialog({
- id: "LogView1",
- title: "Logs",
- url: routerURL+"base_view/gCrudLog/",
- autoOpen: true,
- width: 810,
- height: 600
- });
- };
- app.widget.UserView = function(){
- app.widget.newDialog({
- id: "LogView1",
- title: "Logs",
- url: routerURL+"/base_view/gCrudUser/",
- autoOpen: true,
- width: 810,
- height: 600
- });
- };
- app.widget.viewLogData = function(_i){
- app.widget.jsonView(function(){
- console.log("Dialog Callback!");
- var _json = JSON.parse(logs[_i].Data);
- JSONeditor.start('tree','jform',_json,false,false);
- });
- };
- app.widget.createLogTableWithFileLogs = function(){
- //$("#LogView").html("");
- if(typeof(logs) == 'object'){
- var tbl = "<h2 class='LogViewTitle'>Log View</h2>";
- tbl += "<table class=\"LogViewTable\">";
- //tbl += '<tr class="LogViewHeadTable"><td>TimeStamp</td><td>Message</td><td>Data</td><td>id</td></tr>';
- tbl += '<tr class="LogViewHeadTable"><td>TimeStamp</td><td>Message</td><td>Data</td></tr>';
- for(var i=0;i<logs.length;i++){
- if(isEven(i)){
- tbl += '<tr class="LogViewEvenTable">';
- } else {
- tbl += '<tr class="LogViewOddTable">';
- }
- tbl += "<td>"+getDateString(logs[i].TimeStamp)+"</td>";
- tbl += "<td>"+logs[i].Message+"</td>";
- if(logs[i].Data == null)
- tbl += "<td></td>";
- else{
- //var s = JSON.stringify(logs[i].Data);
- tbl += '<td><a href="javascript:void(0)" onclick="app.widget.viewLogData('+i+')">view</a></td>';
- }
- //tbl += "<td>"+logs[i].id+"</td>";
- //tbl += "<td>"+logs[i].Session_id+"</td>";
- tbl += "</tr>";
- }
- tbl += "</table>";
- //$("#LogView").html(tbl);
- return tbl;
- }
- return false;
- };
- var graphics = null;
- function updateZoomImage(index){
- $('#zoom_image').attr('src', graphics.images[index].url);
- $('#zoom_image').click(function(){ getGraphicUploadDetail(index); });
- }
- function getGraphicUploadDetail(_index){
- var fName = graphics.images[_index].url.slice(graphics.images[_index].url.lastIndexOf('/')+1);
- app.controllers.base.getGraphicUploadDetailFromFileName(fName, jsonViewer);
- }
- app.widget.createGraphicsView = function(){
- function addImage(index){
- try{
- return '<img class="tn" src="'+graphics.images[index].thumb_url+'" onclick="updateZoomImage('+index+')"/>';
- } catch(e){
- console.error("Error processing index: "+index);
- //console.error("Error: "+e);
- }
- }
- var zoom_image = '<img id="zoom_image" width="480" height="360" src="'+graphics.images[0].url+'"/>';
- $('#zoom_box').html(zoom_image);
- $('#zoom_image').click(function(e){
- console.log(e.target.src); //echo src property of image
- //getGraphicUploadDetail(0);
- });
- var img = '';
- for(var i=0;i<graphics.images.length;i++){
- img += addImage(i);
- }
- $('#tn_box').html(img);
- };
- //TODO need to clear the view if data == null
- app.widget.getGraphics = function(){
- app.controllers.base.getImages(app.widget.createGraphicsView);
- };
- function getFileNameFromIndex(_index){
- return graphics.images[_index].url.slice(graphics.images[_index].url.lastIndexOf('/')+1);
- }
- function getFileNameFromImgSrc(img_src){
- return img_src.slice(img_src.lastIndexOf('/')+1);
- }
- app.controllers.base.DelImage = function(index){
- console.log("Deleteing File in Index: "+index);
- app.controllers.base.deleteUploadFileName(getFileNameFromIndex(index), function(e){
- //console.log("Callback Data:"+e);
- //should remove the image from the zoom view, and load the next one in the array
- //and update the info view to match the image
-
- //for now not very efficiant but it'll work on a fast connection
- app.widget.getGraphics();
- });
- };
- app.widget.update_graphicDetails = function(index){
- function getLabel(k, v){
- return '<label>'+k+': '+v+'</label><br/>';
- }
- //'.ImgInfoBox' class name of details box
- //var s = '';
- var s = '<img src="'+AssetDir+'images/del.png" alt="Delete Image" onclick="DelImage('+index+')"/>';
- var o = graphics.images[index];
- for( key in o ){
- s += getLabel(key, o[key]);
- }
- $('#info_box').html(s);
- $('#zoom_image').attr('src', graphics.images[index].url);
- };
- app.controllers.base.getMobileApps = function(_CallBack){
- $.ajax({
- url: routerURL+"base/getApps",
- type: "POST",
- dataType: 'json',
- error: function(jqXHR, textStatus, errorThrown){
- XHR_errorHandler(jqXHR, textStatus, errorThrown);
- },
- success: function(data, textStatus, jqXHR){
- //console.log("success: "+textStatus+", data: "+data);
- if( data.success && isFunction(_CallBack) ) _CallBack(data);
- }
- });
- };
- //titanium Iframe execution code
- function getIframeVar(_windowName, _id){
- var id = 'tiIpad'; if(typeof(id) != 'undefined') id = _id;
- if(typeof(_windowName) != 'undfined')
- return document.getElementById(id).children[id].contentWindow[_windowName];
- return false;
- }
- function evalIframe(_code, _id){
- var id = 'tiIpad'; if(typeof(id) != 'undefined') id = _id;
- return document.getElementById(_id).children[_id].contentWindow.eval(_code);
- }
- app.widget.tiMobileFrame = function (_url, _title, _id, type){
- var id = "tiAndroid";
- var width = 480;
- var height = 800;
- if(typeof(type) == "string"){
- if(type == "ipad"){
- id = 'tiIpad';
- width = 768;
- height = 1024;
- }
- if(type == "iphone"){
- id = 'tiIphone';
- width = 320;
- height = 480;
- }
- }
- if(typeof(id) != 'undefined')
- id = _id;
-
- if(typeof(_url) == 'string'){
- app.widget.newDialog({
- id: _id,
- title: _title,
- url: _url,
- autoOpen: true,
- width: width,
- height: height,
- resizable: false
- });
- console.log("Adding TiDialog");
- console.log('to run code call evalIFrame("'+_id+'", "code");');
- }
- }
- var appData = null;
- function appLinkClicked(e){
- try{
- console.log("click event data: "+e.id); //click event data: javascript:void(0);
- var id = e.id;
- if(typeof(id) == 'string'&& typeof(appData) == 'object'){
- var patt = /[0-9][0-9]*/g;
- var _offset = patt.exec(id);
- var _url = appData.apps.path + "/" + appData.apps.children[_offset];
- var _title = appData.apps.children[_offset];
- var _id = 'Ti' + id;
- console.log("url: "+_url);
- app.widget.tiMobileFrame(_url, _title, _id, "iphone");
- }
- } catch(e){
- console.error("Error: "+e);
- }
- }
- app.widget.createMobileAppView = function(){
- app.controllers.base.getMobileApps(function(data){
- appData = data;
- console.log("message: "+appData.message);
- try{
- $('#TiDemos').html('');
- if(appData.apps.total != appData.apps.children.length){
- console.log("Server error data.total != children.length");
- return false;
- } else{
- //if( typeof(appData.apps.paging) != '') { // }
- var s = '';
- for(var $i=0;$i<appData.apps.total; $i++){
- var click_label = appData.apps.children[$i];
- console.log(click_label);
- s += '<a href="JavaScript:void(0);" onclick="appLinkClicked(this);" id="appDir'+$i+'" >'+click_label+'</a></br>';
- }
- console.log("TiDemos: "+s);
- $('#TiDemos').html(s);
- }
- } catch(e){
- console.error("Error: "+e);
- }
- });
- };
- app.start = function(){
- app.widget.getSessions();
- app.widget.createMobileAppView();
- };
- $(function(){
- //JSONeditor.treeBuilder.path = AssetDir+'JSONeditor2/treeBuilderImages/'; //tried to override but it doesn't seem to work???
- //$('#UploadSubit').button();
- //$('#AddFiles').button();
- //$('#UploadBlock').show();
- app.start();
- });