PDA

View Full Version : use other panel's component,object



tmchedlishvili
2 Jun 2013, 1:38 AM
hello
i have two panel in my window.window, one panel is panel.grid and second panel.panel, on my second panel i have button which displays datas on first grid panel. i try many things but...



and one more question, i have in window.window requares: panel.panel's path & panel.grid's path
and whan i am trying in panel.panel requares: window'window's path it is error ,i can't understand why


if you now about this please give me advice.

vicvolk87
2 Jun 2013, 1:50 AM
If you posted a bit of code, we could help you. From what you are saying it's almost impossible to understand what's wrong.

tmchedlishvili
2 Jun 2013, 2:02 AM
thanks
my codes : the first code

Ext.define('Calc.view.CalcWindow', {
extend: 'Ext.window.Window',
requires: ['Calc.view.HistoryGrid','Calc.view.ButtonsPanel'],
// requires: ['Calc.view.buttonsPanel'],


autoShow: true,
height: 220,
width: 600,
defaultType: 'button',
bodyPadding: 5,
layout: 'column',


initComponent: function() {
var me = this;

// me.print_ans = [];
me.buildItems();
me.callParent();
},


buildItems: function() {
var me = this;
var items = [];



items.push({
xtype: 'historygrid',

columnWidth: 0.5
});

items.push({

xtype: 'buttonspanel',

columnWidth: 0.5
});
me.items = items;


}
});

the second :

Ext.define('Calc.view.ButtonsPanel', {
extend: 'Ext.panel.Panel',
requires: ['Calc.view.HistoryGrid'],
//requires: ['Calc.view.CalcWindow'],





alias: 'widget.buttonspanel',
// defaultType: 'button' ,
title: 'ButtonsPanel',


autoShow: true,
defaultType: 'button',
layout: 'column',


height: 220,
width: 60,


initComponent: function() {
var me = this;
me.buildItems1();


me.callParent();
},


buildItems1: function() {
var me = this;


me.print_ans = [];


var items = [];


items.push({
xtype: 'textfield',
columnWidth: 0.99


});


for (var i = 0; i < 10; i++) {
items.push({
text: i + '',
columnWidth: 0.33,
digit: i,
handler: me.digitHandler,
scope: me
});
}


items.push({
text: '+',
columnWidth: 0.33,
handler: me.plusHandler,
scope: me
});


// begining of new code


items.push({
text: '-',
columnWidth: 0.33,
handler: me.minusHandler,
scope: me
});


items.push({
text: '*',
columnWidth: 0.33,
handler: me.productHandler,
scope: me
});
items.push({
text: '/',
columnWidth: 0.33,
handler: me.divHandler,
scope: me
});


items.push({
text: '=',


columnWidth: 0.33,
handler: me.equalHandler,
scope: me
});
items.push({
text: 'clear',
columnWidth: 0.33,
handler: me.clearHandler,
scope: me
});


items.push({
text: 'show history',
columnWidth: 0.50,


handler: me.history,
scope: me
});


items.push({
text: '.',
columnWidth: 0.15,
handler: me.point,
scope: me
});


me.items = items;


// end _ new code


},


digitHandler: function(btn) {
var me = this;
var resultField = me.down('textfield');


if (me.tmp1 == '=') {
resultField.setValue('');
me.tmp1 = ',';
}
var resultField = me.down('textfield');


var currValue = resultField.getValue();


currValue += btn.digit;


resultField.setValue(currValue);
},


plusHandler: function() {
var me = this;
var resultField = me.down('textfield');
me.print_ans.push(resultField.getValue());
me.print_ans.push('+');
//*****************


me.first_use = me.first_use || 0;


if (me.tmp1 == ',') {
me.operand1 = +resultField.getValue();
}


if (me.first_use == 0) {
me.operand1 = +resultField.getValue();
me.tmp1 = '+';
me.first_use += 1;
resultField.setValue('');
} else {
me.doCalc();
me.tmp1 = '+';
}
},
//**************************************************
/*clearHandler: function() {
var me = this;
me.print_ans = [];
var resultField = me.down('textfield');


var historyGrid = me.down('historygrid');


me.operand1 = 0;


me.first_use = 0;


historyGrid.getStore().removeAll();
resultField.setValue('');
},*/
//*************************************************
productHandler: function() {
var me = this;
var resultField = me.down('textfield');


me.print_ans.push(resultField.getValue());
me.print_ans.push(' * ');
if (me.tmp1 == ',') {
me.operand1 = +resultField.getValue();
}


me.first_use = me.first_use || 0;
if (me.first_use == 0) {
me.operand1 = +resultField.getValue();
me.tmp1 = '*';
me.first_use += 1;
resultField.setValue('');
} else {
me.doCalc()
me.tmp1 = '*';


resultField.setValue('');
}
},
divHandler: function() {
var me = this;
var resultField = me.down('textfield');


me.print_ans.push(resultField.getValue());
me.print_ans.push('/');


if (me.tmp1 == ',') {
me.operand1 = +resultField.getValue();
}


me.first_use = me.first_use || 0;
if (me.first_use == 0) {
var me = this;
me.operand1 = +resultField.getValue();
me.tmp1 = '/';
me.first_use += 1;
resultField.setValue('');
} else {
me.doCalc()
me.tmp1 = '/';
}
},


minusHandler: function() {
var me = this;


var resultField = me.down('textfield');


me.print_ans.push(resultField.getValue());
me.print_ans.push('-');
me.first_use = me.first_use || 0;
if (me.tmp1 == ',') {
me.operand1 = +resultField.getValue();
}


if (me.first_use == 0) {
var me = this;
me.operand1 = +resultField.getValue();
me.tmp1 = '-';
me.first_use += 1;
resultField.setValue('');
} else {
me.doCalc()
me.tmp1 = '-';
}
},

equalHandler: function() {
var me = this;


var resultField = me.down('textfield');
me.print_ans.push(resultField.getValue());
me.doCalc();


me.print_ans.push(' = ', me.operand1);


resultField.setValue(me.operand1);


var resultField = me.down('textfield');


me.tmp1 = '=';


},

//**********************************************
history: function() {
var me = this;
var historyGrid = me.down('historygrid');
var store = historyGrid.getStore();
store.removeAll();


var records = [];
Ext.each(me.print_ans, function(el) {
records.push({
operation: el
});
});


store.loadData(records);
},


//******************************************************



point: function(btn) {


var me = this;


var resultField = me.down('textfield');


if (me.tmp1 == '=') {
resultField.setValue('');
me.tmp1 = ',';
}
var resultField = me.down('textfield');


var currValue = resultField.getValue();


currValue += btn.text;


resultField.setValue(currValue);


},


doCalc: function() {
var me = this;
var resultField = me.down('textfield');
var operand2 = +resultField.getValue();


me.operand1 = me.operand1 || 0;
switch(me.tmp1) {
case '+':
me.operand1 += operand2
break;
case '-':
me.operand1 -= operand2;
break;
case '*':
me.operand1 *= operand2;
break;
case '/':
me.operand1 /= operand2;
break;
}


resultField.setValue(me.squares);
}


});

my goal is show array in grid (history funchtion)



and the third :

Ext.define('Calc.view.HistoryGrid', {
extend: 'Ext.grid.Panel',
requires: ['Calc.store.History'],


alias: 'widget.historygrid',

title: 'History',
height: 220,
width: 400,

initComponent: function() {
var me = this;
me.buildColumns();
me.buildStore();
me.callParent();
},

buildStore: function() {
var me = this;
var store = Ext.create('Calc.store.History');
me.store = store;
},

buildColumns: function() {
var me = this;
var columns = [];

columns.push({
text: 'Operation',
dataIndex: 'operation',
flex: 1
});

me.columns = columns;
}

});

tmchedlishvili
2 Jun 2013, 3:20 AM
my question is not good,

i whant to access pirent's object (panel.)

slemmon
2 Jun 2013, 10:24 PM
I'm not sure where you're getting stuck just yet. You're wanting to access the ButtonsPanel or HistoryGrid's parent window?

tmchedlishvili
2 Jun 2013, 11:34 PM
thanks

I have done this problem my self

solution :

history:function(c){ var getMainWindow = c.findParentByType('calcwindow');

var me = this;
var historyGrid = getMainWindow.down('historygrid');
var store = historyGrid.getStore();
store.removeAll();


var records = [];
Ext.each(me.print_ans, function(el) {
records.push({
operation: el
});
});


store.loadData(records);

}