ExtJS6 Extending Components - extjs6-classic

If I declare a custom component, how to I correctly apply changes to the properties when I create an extension of the component? For example:
Ext.define('GridForm',{
extend: 'Ext.window.Window',
initComponent: function(){
Ext.apply(this,{
title: 'This a test window!'
,height: 400
,width: 400
});
this.callParent();
}
});
Ext.define('LedDataForm',{
extend: 'GridForm',
initComponent: function(){
Ext.apply(this,{
title: 'OK, I want to change it to this.'
});
this.callParent();
}
});
Ext.application({
name : 'MyApp',
launch : function() {
Ext.create('LedDataForm').show();
}
});
In this example, I simply want to change the title of the window when I create "LedDataForm". All comments are appreciated.

Don't write the configs whatever you want to override in init function, instead give it as a default config.
Ext.define('GridForm',{
extend: 'Ext.window.Window',
title: 'This a test window!',// Give this as configs rather than in init function
initComponent: function(){
Ext.apply(this,{
width:400,
height:400
});
this.callParent();
}
});
Ext.define('LedDataForm',{
extend: 'GridForm',
title: 'OK, I want to change it to this.',
initComponent: function(){
Ext.apply(this,{
});
this.callParent();
}
});
Ext.application({
name : 'MyApp',
launch : function() {
Ext.create('LedDataForm',{
title:'testing'
}).show();
}
});

Why not do this:
Ext.define('GridForm',{
extend: 'Ext.window.Window',
title: 'This a test window!',
height: 400,
width: 400
});
Ext.define('LedDataForm',{
extend: 'GridForm',
title: 'OK, I want to change it to this.'
});
Ext.application({
name : 'MyApp',
launch : function() {
Ext.create('LedDataForm').show();
}
});
Simple static configuration can be applied to the class body (2nd argument passed to Ext.define).
initComponent is usually only necessary if you need to calculate values or execute initialization logic.
Also, you could take a look here as it explains a lot: The Class System.

Related

Uncaught TypeError: Failed to execute 'setStart' on 'Range': parameter 1 is not of type 'Node'.(…)

Trying to add class to only selected paragraphs in WordPress Editor.
Added a button called 'Add stylish '<li>' where there is an item called 'Includes'. So my need is to add class to the selected '<p>' when 'Includes' is pressed. Any help will be really grateful. Thanks!
(function() {
tinymce.PluginManager.add('sanjog_custom_tinymce_button', function( editor, url ) {
editor.addButton( 'sanjog_custom_tinymce_button', {
title: 'Add stylish <li>',
type: 'menubutton',
fixedWidth: true,
icon: 'icon dashicons-menu',
menu: [
{
text: 'Includes',
onclick: function() {
tinyMCE.activeEditor.focus();
tinyMCE.activeEditor.dom.addClass(tinyMCE.activeEditor.selection.select('p'),'test');
}
},
]
});
});
})();

WebPro.js Form Analytics Event tracking?

I'm trying to find out if it is possible to implement an Analytics Event to track conversions in the Muse WebPro.js Form widget on successful submit?
Here is the code from the Muse WebPro.js that executes the Form submit:
Muse.Utils.initWidget('#widgetu2128', ['#bp_infinity'], function(elem) {
return new WebPro.Widget.Form(elem, {
validationEvent: 'submit',
errorStateSensitivity: 'high',
fieldWrapperClass: 'fld-grp',
formSubmittedClass: 'frm-sub-st',
formErrorClass: 'frm-subm-err-st',
formDeliveredClass: 'frm-subm-ok-st',
notEmptyClass: 'non-empty-st',
focusClass: 'focus-st',
invalidClass: 'fld-err-st',
requiredClass: 'fld-err-st',
ajaxSubmit: true
});
}); /* #widgetu2128 */
My idea is to insert the Analytics Event tracking code here, as example here:
Muse.Utils.initWidget('#widgetu2128', ['#bp_infinity'], function(elem) {
return new WebPro.Widget.Form(elem, {
validationEvent: 'submit',
errorStateSensitivity: 'high',
fieldWrapperClass: 'fld-grp',
formSubmittedClass: 'frm-sub-st',
formErrorClass: 'frm-subm-err-st',
formDeliveredClass: 'frm-subm-ok-st',
notEmptyClass: 'non-empty-st',
focusClass: 'focus-st',
invalidClass: 'fld-err-st',
requiredClass: 'fld-err-st',
onSuccess: function(){
ga('send', 'event', 'Form', 'Send', '');
},
ajaxSubmit: true
});
}); /* #widgetu2128 */
But it does not seem to be working. Anybody have any suggestions. Can't find any WebPro.js docs or support about this topic online.
Thanks!
//validate
Muse.Utils.initWidget('#widgetu812', function(elem) {
new WebPro.Widget.Form(elem,
{
validationEvent:'submit',
errorStateSensitivity:'high',
fieldWrapperClass:'fld-grp',
formSubmittedClass:'frm-sub-st',
formErrorClass:'frm-subm-err-st',
formDeliveredClass:'frm-subm-ok-st',
notEmptyClass:'non-empty-st',
focusClass:'focus-st',
invalidClass:'fld-err-st',
requiredClass:'fld-err-st',
ajaxSubmit:true
}
);
});/* #widgetu812 */
//submit
<script> $(document).ready(function() {
$("#widgetu812").ajaxComplete(function() {
if (typeof ga !== 'undefined') {
ga('send','event','order','sent');
}
}); }); </script>

Extending own classes

i am develop an app with several windows. Many windows are similar, so i think write a superclass, and extend it.
I have, the superclass:
Ext.define('AM.view.ui.DecoratorAbstract',{
extend: 'Ext.window.Window',
alias: 'widget.decoratorAbstract',
initComponent: function(){
this.title = this.aTitle;
this.resizable = this.cfg[0];
this.closable = this.cfg[1];
this.minimizable = this.cfg[2];
//this.items = this.anItem;
this.callParent(arguments);
}
});
And the subclass:
Ext.define('AM.view.ui.DecoratorForm',{
extend: 'AM.view.ui.DecoratorAbstract',
alias: 'widget.decoratorForm',
initComponent: function(){
this.callParent();
this.buttons = [
{ text:'Guardar', action:'save', iconCls: 'ico-save' },
{ text:'Cancelar', action:'cancel', iconCls: 'ico-cancel' }
];
}
});
Both classes are included in the Controller:
Ext.define('AM.controller.Ui',{
extend: 'Ext.app.Controller',
views: [
'ui.Toolbar',
'ui.Statusbar',
'ui.AlertErr',
'ui.AlertOk',
'ui.AlertWar',
'ui.AlertDelete',
'ui.AlertUndelete',
'ui.DecoratorAbstract',
'ui.DecoratorForm',
'ui.DecoratorGrid'
],
model: [],
store: [],
});
From the Firebug js console i create the subclass:
Ext.create('AM.view.ui.DecoratorForm',{cfg:[true,true,true],aTitle: 'Title'}).show();
The window is showed but, not the buttons.
Any ideas ?.
There are a few things here... First, move this.callParent() to the end of your initComponent. This is because the initComponent further up the inheritance does something with this.buttons, and you are missing out on that by calling callParent before setting the buttons.
Next, you really shouldn't use this cfg thing that you are passing in. Just pass in the config parameters that you want to use, and they will be available:
Ext.define('AM.view.ui.DecoratorAbstract',{
extend: 'Ext.window.Window',
alias: 'widget.decoratorAbstract',
initComponent: function(){
this.callParent(arguments);
}
});
Ext.define('AM.view.ui.DecoratorForm',{
extend: 'AM.view.ui.DecoratorAbstract',
alias: 'widget.decoratorForm',
initComponent: function(){
this.buttons = [
{ text:'Guardar', action:'save', iconCls: 'ico-save' },
{ text:'Cancelar', action:'cancel', iconCls: 'ico-cancel' }
];
this.callParent();
}
});
//to instantiate:
Ext.create('AM.view.ui.DecoratorForm',{
resizable: true,
closable: true,
minimizable: true,
title: 'Title'
}).show();
Anytime you are trying to "trick" the component by using something like that cfg array, you should probably re-think what you're doing and see if there's a smarter way.
One other thing you should look into using is Ext.apply(). It will save a lot of bytes by changing what you had before into something like this:
Ext.apply(this, {
title: 'my title',
resizable: cfg[0],
closable: cfg[1],
///...etc...
})
What if you move
this.callParent(arguments);
To the end of initComponent in your DecoratorForm.

Form not submit

I have a edit user form. The form is loaded from a Json store with this code:
var store = Ext.create('cp.store.form.Paciente',{});
store.load({params:{idUsuario: idPaciente}});
var form = Ext.create('cp.view.form.EditPaciente',{
action: 'bin/paciente/modificar.php'
});
// note: write this lines in the controller
form.on('afterrender',function(form,idPaciente){
form.getForm().loadRecord(store.first());
form.getForm().findField('idUsuario').setValue(idPaciente);
});
var win = Ext.create('cp.view.ui.DecoratorForm',{
aTitle: 'Editar paciente',
aForm: form
});
win.show();
The load code works fine. The submit code is:
var me = this;
console.log('Submit...');
console.log(this.url);
// WHY NOT SUBMIT !!!!
this.getForm().submit({
console.log('submit !');
success: function(form,action){
if(action.result.success === true){
Ext.create('cp.view.ui.AlertOk',{mensaje:action.result.msg}).showDialog();
me.up('decoratorForm').close();
}else{
Ext.create('cp.view.ui.AlertErr',{mensaje:action.result.msg}).showDialog();
}
}
});
So, the submit code starts running. FireBug shows the first and second "console.log", and the "this.url" value is correct. But, the third "console.log" not execute, and the form not send to the server.
Firebug not says 404 error for "this.url" value.
Any ideas ?
Thanks !
Add the form definition:
Ext.define('cp.view.form.EditPaciente',{
extend: 'Ext.form.Panel',
alias: 'widget.editPaciente',
bodyPadding: '5px 5px 5px 5px',
bodyStyle: 'border: none',
fieldDefaults: {
labelWidth: 65,
labelAlign: 'top'
},
initComponent: function(){
this.url = this.action,
this.method = 'POST',
this.items = [ .... ]
this.callParent(arguments);
}
});
You cant put log statements inside object literals.
submit({ <-- This is an object literal
console.log('submit !'); <-- This can not be in an object literal
success: function(form,action){
if(action.result.success === true){
Ext.create('cp.view.ui.AlertOk',{mensaje:action.result.msg}).showDialog();
me.up('decoratorForm').close();
}else{
Ext.create('cp.view.ui.AlertErr',{mensaje:action.result.msg}).showDialog();
}
}
});

Sencha touch 2.0 and iphone : add element to panel dynamically and setActiveItem

I am trying to add dinamically a panel item to a main panel with a card layout which has initially one panel in it.
After one event (a tap) i build dinamically a new panel and I add it to the main panel, after this i try to set the new panel item like the active one via setActiveItem
Things work ok on Android but not on iphone.
Exactly i have this app.js:
Ext.Loader.setConfig({enabled: true});
Ext.setup({
viewport: {
autoMaximize: false
},
onReady: function() {
var app = new Ext.Application({
name: 'rpc',
appFolder: 'app',
controllers: ['Home'],
autoCreateViewport: false,
launch: function () {
Ext.create('Ext.Panel',{
fullscreen: true,
layout: {
type : 'card',
animation:{
type:'slide'
,duration :3000
}
},
defaults: { /*definisce le caratteristiche di default degli elementi contenuti..??*/
flex: 1
},
items:[{
title: 'Compose',
xtype: 'griglia'
}]
});
}
});
}
});
In a controller i have
.....
.....
var grigliaPan=button.up('griglia');
var mainPan=grigliaPan.up('panel');
var html=
'<img src="img/'+segnoScelto+'_big.png" />'
+'<h1>'+segnoScelto+'</h1>'
+'<p>'+previsione+'</p>'
+'</br></br>';
if (typeof mainPan.getComponent(1) == 'undefined'){
var previsioPan = Ext.widget('previsio');
previsioPan.setHtml(html);
//here i create a button for going home panel
var backButton=new Ext.Button({
ui : 'decline',
alias: 'widget.backbutton',
text: 'Home Page',
width : 150,
height:100
})
previsioPan.add(backButton);
var it=mainPan.getItems();
alert (it['keys']); //this prints : ext-griglia-1
mainPan.add(previsioPan);
var it=mainPan.getItems();
alert (it['keys']); //this prints : ext-griglia-1,ext-previsio-1
//
}
mainPan.getLayout().setAnimation({type: 'slide', direction: 'left', duration:1000});
//mainPan.setActiveItem(1);
var pree=mainPan.getAt(1);
//pree.show();
//mainPan.setActiveItemm(pree);
mainPan.setActiveItem('ext-previsio-1');
The three form of setActiveItem() are ok for Android and falls with iPhone. Can somebody please show me what is the right way to set the new active item added dinamically on the iphone ?
The problem should not be with the add() function cause i can see the new item via the getItems() added in main panel after the add().
by following code you can understand that thisCell is added later after creation of thisRow.
var thisRow = new Ext.Panel({
layout: { type: 'hbox', align: 'stretch', pack: 'center' },
id: 'row' + (rowCount + 1),
defaults: { flex: 1 }
});
// Now we need to add the cells to the above Panel:
var thisCell = new Ext.Panel({
cls: 'dashboardButton',
layout: { type: 'vbox', align: 'center', pack: 'center' },
items: [{
xtype: 'image',
src: 'some image url',
height: '70px',
width: '100px',
}]
});
thisRow.add(thisCell);
hope this will help you to achieve your desired output...