Why can't I apply property to my own custom class in extjs4? - extjs4.1

Can someone help me out to resolve the problem that I'm not able to apply some of properties to my own custom class. Here is my source:
Ext.define('com.amkor.web.common.client.GridPanel', {
alias : 'Web.common.client.GridPanel',
extend : 'Ext.grid.Panel',
isCheckbox : false,
initComponent : function(){
var me = this;
var sm = (me.isCheckbox)?Ext.create('Ext.selection.CheckboxModel'):'';
Ext.apply(me, {
title : 'Grid',
width : 560,
height : 300,
selModel : sm,
frame : false,
border : false,
forceFit : true,
columnLines : true,
autoLoad : false,
autoDestory : true
});
me.callParent(arguments);
},
getGridSelection : function(){
return this.getSelectionModel().getSelection();
},
removeGridSelection : function(){
this.getStore().remove(this.getGridSelection());
}
});
As you see, I defined new custom class by extending Ext.grid.Panel, and then I define new custom class by extending custom class com.amkor.web.common.client.GridPanel.
Ext.define('EvaluationApp.view.EvaluationGrid', {
extend : 'com.amkor.web.common.client.GridPanel',
xtype : 'EnhancementGrid',
initComponent : function(){
Ext.apply(this, {
id : 'evalGrid',
width : 556,
height : 290,
title : 'Wow',
columns : columns,
features : [Ext.create('Ext.grid.feature.Grouping', {
groupHeaderTpl : '<div align="left">연도 : <font color="green">{[values.rows[0].grp_year]}</font> ({rows.length}) </div>'
})]
});
this.callParent(arguments);
}
});
I wanted to change title from "Grid" to "Wow", but it does not apply.
Please give me some advice.

Ext.define('com.amkor.web.common.client.GridPanel', {
alias : 'Web.common.client.GridPanel',
extend : 'Ext.grid.Panel',
isCheckbox : false,
title: 'Grid',
initComponent : function(){
var me = this;
var sm = (me.isCheckbox)?Ext.create('Ext.selection.CheckboxModel'):'';
Ext.apply(me, {
width : 560,
height : 300,
selModel : sm,
frame : false,
border : false,
forceFit : true,
columnLines : true,
autoLoad : false,
autoDestory : true
});
me.callParent(arguments);
},
getGridSelection : function(){
return this.getSelectionModel().getSelection();
},
removeGridSelection : function(){
this.getStore().remove(this.getGridSelection());
}
});
Notice how I moved the title config from inside the Ext.apply to the class definition. Now, when this grid is created, if a title is passed in, that title will be used. If no title is passed in, the title will default to 'Grid'.
To understand what is happening here, you need to understand what Ext.apply is doing. Ext.apply takes the second object passed in, and copies its properties onto the first object passed in. More info can be found in the docs: http://docs.sencha.com/extjs/4.2.2/#!/api/Ext-method-apply .
So, in the code above, Ext.apply is copying properties onto me (which equals this), and is taking those properties from the object you are passing in as the second argument, which is displayed below.
{
width : 560,
height : 300,
selModel : sm,
frame : false,
border : false,
forceFit : true,
columnLines : true,
autoLoad : false,
autoDestory : true
}
So, anything listed in the above object will overwrite the same properties found in this. When you create or extend the above class, any properties added to it (such as your example of setting title: 'Wow') will be added directly to this. As I said before, any properties defined in the second object will overwrite anything defined in this, so that is why when you put title: 'Grid' in the second object, it just overwrote any title property you passed in when extending the class.

Related

How to set a value into a openerp form view field from javascript

this is the code i use to call the form view:
get_view_form_dimension: function() {
var self = this;
var action_manager = new openerp.web.ActionManager(this);
var dialog = new openerp.web.Dialog(this, {
width: 800,
buttons : [
{text: _t("Cancel"), click: function() { $(this).dialog('destroy'); }},
{text: _t("Save"), click: function() {
var form_view = action_manager.inner_viewmanager.views.form.controller;
form_view.do_save(function() {
$.jstree._reference("#new_tree").destroy();
self.get_tree_structure();
});
$(this).dialog('destroy');
}}
]
}).open();
action_manager.appendTo(dialog.$element);
action_manager.do_action({
res_model : 'df.bi.dimension',
res_id: self.process_id,
views : [[false, 'form']],
type : 'ir.actions.act_window',
flags : {
search_view: false,
sidebar : false,
views_switcher : false,
action_buttons : false,
pager: false
}
});
},
how can i set values into the form that this method will rise ?? or in case that exist other solution please tell me ? sorry for my english!
Add a context field to your do_action call with default values, like this:
context: {'default_account_id': 5, 'default_name': 'hello'},

One view and multiple controller actions for the same button in EXTJS

Am having a delete button in my EXTJS Application. On clicking the button, am opening a confirmation form, asking the user are they sure to delete the item. The delete button is a part of many forms in my Application. And irrespective of the form being used, am opening the confirmation window.
And on clicking the yes button in the confirmation window, i want to do some action. But these actions have to be specific to the form that was opened first.So, am confused about how to use the same view, the same button, but different actions depending upon the first form that was opened.
View: This is the window that opens on clicking the delete button in any of the forms
Ext.define('app.view.GenMessageWin', {
extend : 'Ext.panel.Panel',
alias : 'widget.genmessagewin',
var fp = {
xtype : 'panel',
itemId : 'MSGPANEL',
width : Width,
height : 150,
cls : 'msg effect1',
layout : 'form',
border : false,
items : [{
xtype : 'panel',
//cls : 'winTitle',
html : msgTxt,
border : 0
}, {
xtype : 'form',
itemId : 'MSGFORM',
border : false,
title : '',
buttonAlign : 'center',
fieldDefaults : {
msgTarget : 'side',
labelWidth : 110,
size : 30
},
buttons : [{
text : LANG.BTYES,
iconCls : 'icon-tick-tb',
iconAlign : 'right',
cls : 'tip-btn',
action : 'delete',
id : 'BTYES'
}, {
text : LANG.BTNO,
iconCls : 'icon-cross-tb',
iconAlign : 'right',
cls : 'tip-btn',
action : 'notDelete',
id : 'BTNO'
} ]
Controller
init : function() {
this.control({
'button[action = delete]' : {
click : this.delete
},
'button[action = notDelete]' : {
click : this.notDelete
},
So, in the delete action, we have to determine which form has been opened in the first place, and then delete the data accordingly.
You have 3 options:
1) Make the selector more specific:
'form1 button[action=delete]': {
click: this.form1Delete
},
form1Delete: function(){
this.showMsg(function() {
// form 1 delete
});
}
2) Traverse back up the component hierarchy and find the open form
onDelete: function(btn) {
var form = btn.up('form'); // find an xtype form or subclass
if (form.someCondition) {
//foo
} else {
//bar
}
}
3) As suggested by Dmitry. You'll need to convert it over to 'MVC style'.
Ext.define('ConfirmButton', {
extend: 'Ext.button.Button',
title: '',
msg: '',
requires: ['Ext.window.MessageBox'],
initComponent: function(){
this.callParent();
this.on('click', this.handleClick, this);
},
handleClick: function(){
Ext.MessageBox.confirm(this.title, this.msg, this.checkResponse, this);
},
checkResponse: function(btn){
if (btn == 'yes') {
this.fireEvent('confirm', this);
}
}
});
Ext.onReady(function(){
var btn = new ConfirmButton({
renderTo: document.body,
text: 'Foo',
title: 'Should I',
msg: 'Are you sure'
});
btn.on('confirm', function(){
console.log('Do something');
})
});
I am doing something similar; I simply use the native Ext.Msg class
Controller code
,onDelete: function() {
var me = this;
Ext.Msg.show({
title:'Really shure?',
msg: 'Really wanna do this?',
buttons: Ext.Msg.YESNO,
icon: Ext.Msg.QUESTION,
closable: false,
fn: function(btn) {
if (btn == 'yes') {
me.deleteRecord();
}
},
scope: me
});
}
,deleteRecord: function() {
var me = this,
store = Ext.StoreMgr.lookup('datastore');
store.remove(me.selectedRecord);
store.sync();
}
I would recommend you to keep all logic concerning this within the controller. I your case it'seems that's no problem, cause you just catching the button-events. You problem may be that all controllers catch these, if you are using totally the same window.
You can solve this for example by creating the action property value dynamically when creating the window. Like action='onDeleteCar'
I think you should embed the 'confirmation' functionality inside the button, i.e. create your own ConfirmButton class that would first fire a dialog upon pressing and executing the passed handler only if the dialog exited with "yes".
Here is the example implementation:
Ext.define('My.ConfirmButton', {
extend: 'Ext.button.Button',
alias: 'widget.confirmbutton',
dlgConf: {
title: 'Are you sure?',
msg: 'Are you sure you want to delete this?',
buttons: Ext.Msg.YESNO,
closable: false
},
initComponent: function() {
this.callParent(arguments);
// remember the originally passed handler
this.origHandler = this.handler;
this.origScrope = this.scope;
// override current handler to fire confirmation box first
this.handler = this.confirmHandler;
this.scope = this;
},
confirmHandler: function(me, e) {
// show dialog and call the original handler only on 'yes'
Ext.Msg.show(Ext.applyIf({
fn: function(buttonId) {
if(buttonId == 'yes') {
me.origHandler && me.origHandler.call(me.origScope || me, me, e)
}
},
scope: me
}, this.dlgConf))
},
// Method used to dynamically reassign button handler
setHandler: function(handler, scope) {
// remember the originally passed handler
this.origHandler = this.handler;
this.origScrope = this.scope;
// override current handler to fire confirmation box first
this.handler = this.confirmHandler;
this.scope = this;
return this;
},
});
Here is the sample usage:
Ext.create('My.ConfirmButton', {
text: 'Delete me',
renderTo: Ext.getBody(),
handler: function() {
alert('Aww, you deleted something! :(')
}
});
As you see, the confirmation logic is hidden from the outside world, you use this button exactly like you would use a regular Ext.Button (by passing a handler to it). Also, you can override the configuration of the dialog that the button fires (you may want to adjust it to your needs, e.g. allow passing record name to the dialog for a friendlier UI).
Note that the code isn't thoroughly tested, some cases might be left uncovered.
UPD. You need to add an alias (former xtype) to the component class definition so you can use it in ComponentQuery in your controller code, e.g.
this.control({
'confirmbutton[action = delete]' : {
click : this.delete
},
'confirmbutton[action = notDelete]' : {
click : this.notDelete
}
})
The final solution that i used was to declare variables using the global namespace so that they can be accessed from anywhere. On opening the first form, i get the data from the form using the record variable, and assign them a global name like
App1.Var1 = record.data.id;
And, on opening the delete window, these variables can be accessed by App1.Var1 when the buttons are clicked.

Sencha touch remove group header and increase gap

How can I remove Sencha touch grouped list header and increase the gap.
Define a custom class for your list and add the css for that class in your css file.
Off-course, with grouped config options set to true if u r using a store and add desired fieldname to be grouped.
View:
Ext.define('app.view.Temp', {
extend : 'Ext.List',
xtype : 'temp',
config : {
title : 'Temp',
cls : 'x-contacts',
disableSelection: true,
grouped : true,
store : 'YourStore',
ui : 'round',
cls:'modifiedHeader',
//custom css classname
itemTpl : ['<span>{field_name}</span>'].join('')
}
});
Store:
Ext.define('app.store.YourStore', {
extend : 'Ext.data.Store',
config : {
model : 'app.model.Temp',
autoLoad : true,
storeId:'YourStore',
groupField: 'field_name',
proxy : {
type : 'ajax',
url : 'link/to/api'
}
}
});
app.css
.modifiedHeader .x-list-header {
//your desired css here
display:none;//If you want to hide the header
}

EXTJS 4 - provide data for XTemplate

I am new to extjs and I am having trouble when feeding a template with data.
var header = new Ext.Template("<div><b>{name}</b></div>");
header.compile();
var description = new Ext.Template("<div><b>{description}</b></div>");
description.compile();
Ext.define('ActivityWindow', {
extend : 'Ext.window.Window',
id : 'detActWin',
layout : 'border',
config :{
resultRecord : null
},
defaults :{
xtype : 'panel'
},
constructor: function (args){
this.initConfig(args);
this.callParent();
},
items : [
{
tpl : header,
itemId : 'activityHeader',
region : 'north',
data : this.resultRecord
},
{
html : 'partecipantsList',
itemId : 'activityPartecipants',
region : 'east'
},
{
html : 'description',
region : 'center'
}
]
});
var winDetAct = Ext.create(ActivityWindow, { resultRecord: entry});
alert(winDetAct.getResultRecord().get('name')); //it shows the field name
winDetAct.show();
where resultRecord = {name : 'topText', description: 'rightText'}
I would like to pass this resultRecord to the Window class and have the items using this data. the resultRecord in the window class is well set, because the alert shows the correct data.
but this line is like ignored,
data : this.resultRecord
questions:
1 - How can I feed the template in item 1 of the window with the data from the variable resultRecord ?
2 - Is there a proper way to do this?
thank you very much,
Gabriel
The issue you are seeing is that this.resultRecord is undefined because "this" context is not yet available as the component to your config. You have to call initComponent and inside that you can have this.Myproperty reference. Her is your code modified to work correctly:
http://jsfiddle.net/dbrin/HTAWP/1/

Why does this Ext.grid.Panel crash?

This crashes:
var grdMakes = Ext.extend(Ext.grid.Panel, {
constructor: function(paConfig) {
}
}
This does not:
var grdMakes = Ext.extend(Ext.grid.Panel, {
}
The crash is:
Uncaught TypeError: Cannot read property 'added' of undefined
Why does adding a constructor cause it to crash? I can do it with other objects like:
var pnlMakesMaint = Ext.extend(Ext.Panel, {
constructor: function(paConfig) {
}
} // just fine
EDIT
To clarify what I want to do is that I want to be able to instantiate an object with the option to override the defaults.
var g = new grdMakes({}); // defaults used
var g = new grdMakes({renderTo: Ext.getBody()}); // renderTo overridden
This is working for everything except the Ext.grid.Panel
Also, I'm using ExtJS 4
SOLUTION
Turns out, extend is deprecated in ExtJS 4. So I used this and it works:
Ext.define('grdMakes', {
extend: 'Ext.grid.Panel',
constructor: function(paConfig) {
var paConfig = Ext.apply(paConfig || {}, {
columns: !paConfig.columns ? [{
header: 'Makes',
dataIndex: 'make'
}, {
header: 'Description',
dataIndex: 'description'
}]: paConfig.columns,
height: !paConfig.height ? 400 : paConfig.height,
renderTo: !paConfig.renderTo ? Ext.getBody() : paConfig.renderTo,
store: !paConfig.store ? stoMakes : paConfig.store,
title: !paConfig.title ? 'Makes' : paConfig.title,
width: !paConfig.width ? 600 : paConfig.width
});
grdMakes.superclass.constructor.call(this, paConfig);
}
}
Ok.But your code seems like ExtJS3.Because Ext.extend is depreceated in ExtJS4 version.Instead of extend you can use define.For reference you can check the following url:
http://docs.sencha.com/ext-js/4-0/#/api/Ext-method-extend
Afaik,for overriding default options,this is not the perfect way.You need to use Ext.override.
For example:
Ext.override(Ext.grid.Panel,{
lockable : true
});
Like above you have to override the default options.