init.js 9.29 KB


Ext.require('Ext.container.Viewport');

Ext.application({
    name: 'App',
    appFolder: 'app',

    autoCreateViewport:true,
    controllers: ['grdRouts','grdLogEvent','grdNotifications','grdLiveSubscribers','grdGSMNotification'],

    launch: function () {
        Ext.Loader.setConfig({ enabled: true });


        var objAjax = null;


	
	// -------------------------------Basic Autarize---------------------------------------- //

	// настройки для proxy; 
	
		//	Ext.data.proxy.Proxy( [config] ) :
	
  
	

	
	//Ext.onReady(function() {

   // var auth = "Basic " + 'user' + ':' + 'password';

    // Create store          
   // var myStore = new Ext.data.JsonStore({
        // Load data at once
      //  autoLoad: true,
        // Override default http proxy settings
      //  proxy: new Ext.data.ScriptTagProxy({
            // Call web service method using GET syntax
         //   url: 'http://myotherdomain.com/something.xml',
       //     headers : { Authorization : auth }
      //  })
   // });
//});
	
	
	//var auth = 'Basic ' + Base64.encode(user + ':' + pass);
//Ext.Ajax.request({
   // url : url,
   // method : 'GET',
   // headers : { Authorization : auth }
//});
	
	
	
	
	
	
	
	
	//Ext.Ajax.useDefaultXhrHeader = false;
//	Ext.Ajax.withCredentials=true;
	
	/*

	
var win = new Ext.Window({
  layout:'fit',
  closable: false,
  draggable: false,
  resizable: false,
  width: 425,
  plain: true,
  border: false,
  modal:true,
  bbar: [{
    xtype: 'tbtext',
    text: ' ©    2013 - Панель управления'
  }],
  items: [ ]
//}).show();
});
	
	
	
function make_base_auth(user, pass) {
  var tok = user + ':' + pass;
  var hash = $.base64.encode(tok);
  
  console.log(hash);
  return "Basic " + hash;
}


var auth = make_base_auth('username','password');
var url = "http://localhost:9099/api/TestBasic";

$.ajaxSetup({
	beforeSend : function(jqXHR, settings) {
 jqXHR.setRequestHeader('Authorization', auth);
	}
 });

*/
//$.ajax({
  
  //  method : 'GET',
	//dataType: "json",
	//async: false
   // beforeSend : function(jqXHR, settings) {

	//$.extend(settings, { headers: { "Authorization": auth} });
   //    jqXHR.setRequestHeader('Authorization', auth);
   // }
//});
	

	/*
	
		function getAuthorizationHeader(username, password) {
            var authType;

            if (password == "") {
                authType = "Cookie " + $.base64.encode(username);
            }
            else {
                var up = $.base64.encode(username + ":" + password);
                authType = "Basic " + up;
            };
            return authType;
        };
 
        function ajaxSuccessHandler(data) {
            alert(data);
        };
 
        function ajaxErrHandler(jqXHR, textStatus, errorThrown) {
            alert(errorThrown + " : " + textStatus);
        }
		
		
      //  function runTest() {
 
         	var username = "username";
            var password ="password";
		  $.ajax({
                url: "http://localhost:9099/api/TestBasic",
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Authorization", getAuthorizationHeader(username, password));
                },
                success: ajaxSuccessHandler,
                error: ajaxErrHandler
            });

     //   };
	
	//runTest();
	*/
	
	//------------------------------------------------------------------------------------- //
	/*var token = "username:password"; 
	var hash = Base64.encode(token); 
	var header = "Basic " + hash; 
	console.log(header);
        $.ajax({
			type: "POST",
            url: "http://localhost:9099/api/TestBasic/Login",
            dataType: "json",
			async: false,
            beforeSend: function(xhr) {
                xhr.setRequestHeader("Authorization: ", header);
            },
            success: function(data) {
                alert(data);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert('Ошибка');
            }
        });
   
*/
	
	
/*	
	$.ajax
({
  type: "GET",
  url: "http://localhost:9099/api/TestBasic/Get",
  dataType: 'json',
  async: false,
  username: 'username',
  password: 'password',
  success: function (){
    alert('Thanks for your comment!'); 
  }
});
	*/

	/*
	
	var username = 'username';
	var password = 'password';  

function make_base_auth(user, password) {
  var tok = user + ':' + password;
  var hash = btoa(tok);
  return "Basic " + hash;
}
$.ajax
  ({
    type: "GET",
    url: "http://localhost:9099/api/TestBasic/Get",
    beforeSend: function (xhr){ 
        xhr.setRequestHeader('Authorization', make_base_auth(username, password)); 
    },
	  dataType: 'json',
  async: false,
    success: function (){
        alert('Thanks for your comment!'); 
    }
});
	*/

	/*
                $.ajax({
				url: "http://localhost:9099/api/TestBasic/",
			      beforeSend: function (xhr) {
                        xhr.setRequestHeader("authenticationToken", "326ED626-0E95-4C75-A456-B42E605FF929");
                    },   
            type: "GET",
            success: function (data) {
               // ret = data;
            }
        });
     */
	 /*
			$.ajax({
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader("authenticationToken", "326ED626-0E95-4C75-A456-B42E605FF929");
                    },
                    url: "http://localhost:9099/api/TestBasic/Get",
                    type: "POST",
                    statusCode: {
                        200: function (result) {
                            alert(result);
                        },
                        401: function (result) {
                            alert("Access was denied");
                        }
                    }
                });
          
	*/
	
        //-------------------------------------------------------------------------// 

        /*
        var TaskRunner = function (interval) {
            interval = interval || 10;
            var tasks = [],
                removeQueue = [],
                id = 0,
                running = false,

                stopThread = function () {
                    running = false;
                    clearInterval(id);
                    id = 0;
                },
                startThread = function () {
                    if (!running) {
                        running = true;
                        id = setInterval(runTasks, interval);
                    }
                },
                removeTask = function (t) {
                    removeQueue.push(t);
                    if (t.onStop) {
                        t.onStop.apply(t.scope || t);
                    }
                },
                runTasks = function () {
                    var rqLen = removeQueue.length,
                        now = new Date().getTime();
                    if (rqLen > 0) {
                        for (var i = 0; i < rqLen; i++) {
                            tasks.remove(removeQueue[i]);
                        }
                        removeQueue = [];
                        if (tasks.length < 1) {
                            stopThread();
                            return;
                        }
                    }
                    for (var i = 0, t, itime, rt, len = tasks.length; i < len; ++i) {
                        t = tasks[i];
                        itime = now - t.taskRunTime;
                        if (t.interval <= itime) {
                            rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
                            t.taskRunTime = now;
                            if (rt === false || t.taskRunCount === t.repeat) {
                                removeTask(t);
                                return;
                            }
                        }
                        if (t.duration && t.duration <= (now - t.taskStartTime)) {
                            removeTask(t);
                        }
                    }
                };

            this.start = function (task) {
                tasks.push(task);
                task.taskStartTime = new Date().getTime();
                task.taskRunTime = 0;
                task.taskRunCount = 0;
                startThread();
                return task;
            };

            this.stop = function (task) {
                removeTask(task);
                return task;
            };

            this.stopAll = function () {
                stopThread();
                for (var i = 0, len = tasks.length; i < len; i++) {
                    if (tasks[i].onStop) {
                        tasks[i].onStop();
                    }
                }
                tasks = [];
                removeQueue = [];
            };
        };
		
		

       var  ReloadLogGridEvent = function () {
			
			
		    var grdLogEvent = Ext.create('App.view.grdLogEvent');
			grdLogEvent.store.reload();
			
			var grdLiveSubscribers = Ext.create('App.view.grdLiveSubscribers');
			grdLiveSubscribers.store.reload();

			var res = Varification.run();
			
			var grdNotifications = Ext.create('App.view.grdNotifications');
			grdNotifications.store.reload();

  
  }

        var TaskReloadLogGridEvent = {
            run: ReloadLogGridEvent,
            interval: 60000,
        }
        var runnerTaskRequestReloadLogGridEvent = new TaskRunner();
        runnerTaskRequestReloadLogGridEvent.start(TaskReloadLogGridEvent);
		
		*/
  
    }// end launch

});