/*
 * File: app/controller/GUIController.js
 *
 * This file was generated by Sencha Architect version 3.0.2.
 * http://www.sencha.com/products/architect/
 *
 * This file requires use of the Ext JS 4.2.x library, under independent license.
 * License of Sencha Architect does not include license for Ext JS 4.2.x. For more
 * details see http://www.sencha.com/license or contact license@sencha.com.
 *
 * This file will be auto-generated each and everytime you save your project.
 *
 * Do NOT hand edit this file.
 */

Ext.define('MyApp.controller.GUIController', {
	extend: 'Ext.app.Controller',

	refs: [
		{
			ref: 'treegrid',
			selector: '#treegrid'
		},
		{
			ref: 'viewRuleHistoryButton',
			selector: '#viewRuleHistoryButton'
		},
		{
			ref: 'treegridSearch',
			selector: '#treegridSearch'
		}
	],

	init: function(application) {
		//add listener to treegrid
		this.control({
		    '#treegrid': {
		        selectionchange: function(model, selected, eOpts) {
		            this.selectionHasChanged(selected);
		        }
		    }
		});
	},

	onLaunch: function() {
		/*
		var task = new Ext.util.DelayedTask(function(args){
		    var mygrid = args.grid;
		    mygrid.getStore().load();
		    mygrid.expandAll();
		});
		var mygrid = this.getTreegrid();
		task.delay(3000, null, null, [{grid: mygrid}]);
		*/
	},

	selectionHasChanged: function(selected) {
		this.getViewRuleHistoryButton().disable();

		if(selected.length == 1) {
			var rec = selected[0];
			if(!rec.isLeaf()) { //must be a group then
				if(!rec.isExpanded() && rec.isExpandable())
					rec.expand();
				console.log(rec);
			}
			else { //is risk
				this.getViewRuleHistoryButton().enable();
			}
		}

	}

});
