Output tooltip if click on tool - extjs

Hello I have a window with tools. I have the tool: 'help', and when clicking on it I want it to output a tooltip with text from my HTML file, but actually it shows alert('Help'), and it doesn't output from the file:
tools: [
{
type: 'refresh',
name: 'refresh',
tooltip: 'reload'
},
{
type: 'help',
handler: function (event, toolEl, panel) {
alert('Help');
var tooltips = [{
target: 'tip1',
html: 'A very simple tooltip'
}, {
target: 'ajax-tip',
width: 200,
autoLoad: {url: '/help/note/help.html'},
dismissDelay: 15000 // auto hide after 15 seconds
},
];
Ext.each(tooltips, function (config) {
Ext.create('Ext.tip.ToolTip', config);
});
},
}
]
This picture shows what I actually want:

You need to load the html file in an Ajay request from server and then create the tooltip in the success callback.
Ext.Ajax.request({
url: '/help/note/help.html',
success: function(response){
// in the success callback you get the html text in the response.responseText
// and then you can create a tooltip with the content of it
}
});
So you can do the following in the callback
var html = response.responseText;
var tooltip = {
target: 'ajax-tip',
width: 200,
html: html,
dismissDelay: 15000 // auto hide after 15 seconds
};
The full code should be
{
type: 'help',
handler: function (event, toolEl, panel) {
Ext.Ajax.request({
url: '/help/note/help.html',
success: function (response) {
var html = response.responseText;
var tooltip = {
target: 'ajax-tip',
width: 200,
html: html,
dismissDelay: 15000 // auto hide after 15 seconds
};
Ext.create('Ext.tip.ToolTip', tooltip);
}
});
}
}

Related

How to add additional keys to the itemselector keymap EXTjs?

Is there a solution to extend the KeyMap of the ItemSelector?
I would like to add a keymap(like pageUp and pageDown keyEvent in itemselector) that when I press the letter 'A-Z' will take me to the item that starts with the letter pressed and select it.
You can use the following override (fiddle sample) to achieve it. It will not work correctly on view sore reload. And you will have to define the record search record field. In case of complicated view templates you can remove hardcoded search function and use it as a setting.
Ext.define('overrides.view.NavigationModel', {
override: 'Ext.view.NavigationModel',
searchRecordField: false,
initKeyNav: function (view) {
var me = this;
// Drive the KeyNav off the View's itemkeydown event so that beforeitemkeydown listeners may veto.
// By default KeyNav uses defaultEventAction: 'stopEvent', and this is required for movement keys
// which by default affect scrolling.
var keyNavConfig = {
target: view,
ignoreInputFields: true,
eventName: 'itemkeydown',
defaultEventAction: 'stopEvent',
processEvent: me.processViewEvent,
up: me.onKeyUp,
down: me.onKeyDown,
right: me.onKeyRight,
left: me.onKeyLeft,
pageDown: me.onKeyPageDown,
pageUp: me.onKeyPageUp,
home: me.onKeyHome,
end: me.onKeyEnd,
space: me.onKeySpace,
enter: me.onKeyEnter,
A: {
ctrl: true,
// Need a separate function because we don't want the key
// events passed on to selectAll (causes event suppression).
handler: me.onSelectAllKeyPress
},
F: me.onAlphabetKeyPress,
scope: me
};
if(this.view.searchRecordField) {
keyNavConfig = Ext.Object.merge(keyNavConfig, this.getAdditionalKeyNav());
}
me.keyNav = new Ext.util.KeyNav(keyNavConfig);
},
getAdditionalKeyNav: function() {
var keyNav = {};
this.view.getStore().each(function(record) {
var firstLetter = record.get(this.view.searchRecordField)[0].toUpperCase();
if(!keyNav[firstLetter]) {
keyNav[firstLetter] = this.onAlphabetKeyPress
}
}, this);
return keyNav;
},
onAlphabetKeyPress: function(keyEvent) {
const key = keyEvent.event.key;
var foundRecordIndex = this.view.getStore().findBy(function(record) {
return record.get('title').toLowerCase().indexOf(key) === 0;
}, this);
if(foundRecordIndex > -1) {
this.setPosition(foundRecordIndex, keyEvent);
}
}
});
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.define('ListItem', {
extend: 'Ext.data.Model',
fields: [{
name: 'src',
type: 'string'
}, {
name: 'caption',
type: 'string'
}]
});
Ext.create('Ext.data.Store', {
id: 'ListItemsStore',
model: 'ListItem',
data: [{
title: "One"
}, {
title: "Two"
}, {
title: "Three"
}, {
title: "Four"
}, {
title: "Three"
}, ]
});
var imageTpl = new Ext.XTemplate(
'<tpl for=".">',
'<div style="margin-bottom: 10px;" class="thumb-wrap">',
'<span>{title}</span>',
'</div>',
'</tpl>'
);
Ext.create('Ext.view.View', {
store: Ext.data.StoreManager.lookup('ListItemsStore'),
tpl: imageTpl,
itemSelector: 'div.thumb-wrap',
emptyText: 'No images available',
// Search Record Field
searchRecordField: 'title',
renderTo: Ext.getBody()
});
}
});

Extjs Tool tip for chart category label

Here is the Label object
,
label: {
rotate: {
degrees: 90
},
renderer: function(v){
var toolTip = Ext.create('Ext.tip.ToolTip', {
target: this,
html: v,
anchor: 'left',
dismissDelay: 0,
showDelay: 0,
autoHide: false
});
toolTip.on('show', function(){
var timeout;
toolTip.getEl().on('mouseout', function(){
timeout = window.setTimeout(function(){
toolTip.hide();
}, 500);
});
toolTip.getEl().on('mouseover', function(){
window.clearTimeout(timeout);
});
Ext.get(targetId).on('mouseout', function(){
timeout = window.setTimeout(function(){
toolTip.hide();
}, 500);
});
});
if(v.length>10)
return Ext.util.Format.substr(v,0,10) +'...' ;
}
}
This code is not not creating the tool tip. No error occurs. Is there any other method to create the category label tool tip.
Thanks,
Anish

Querying on DirectChildrenCount Rally JS SDK

I checked out some other questions posted previously but couldn't find a relevant answer. So here I am posting again: Here's my code:
Ext.create('Rally.data.WsapiDataStore',{
autoLoad: true,
model: 'HierarchicalRequirement',
limit: '500',
fetch: ['ObjectID','DirectChildrenCount','FormattedID'],
filters:[{property: 'DirectChildrenCount', operator: '=', value: 0}], //tried both "0",'0'
listeners: {
load: function(store,data,success){
var data_length = data.length;
console.log("Number = ", data);
}
}
});
Result is an empty array. Furthermore, the result did not contain the field "DirectChildrenCount" at all, even though I am fetching it.
I tried your code without any changes, and it returned 300+ items. DirectChildrenCount was included in the result. It was tested against "2.0rc2" and "2.0rc1" with the same result. Here is screenshot from Chrome's DevTools:
Here is another short app where a grid of stories updated since yesterday is built, filtered by the same condition.
{property: 'DirectChildrenCount', operator: '=', value: 0}
js file is below:
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
var millisecondsInDay = 86400000;
var currentDate = new Date();
var startDate = new Date(currentDate - millisecondsInDay);
var startDateUTC = startDate.toISOString();
Rally.data.ModelFactory.getModel({
type: 'UserStory',
success: function(model) {
this.grid = this.add({
xtype: 'rallygrid',
itemId: 'grid',
model: model,
columnCfgs: [
'FormattedID',
'Name',
'Owner',
'LastUpdateDate'
],
storeConfig: {
filters: [
{
property: 'LastUpdateDate',
operator: '>',
value: startDateUTC
},
{
property: 'DirectChildrenCount',
operator: '=',
value: 0
},
]
}
});
},
scope: this
});
console.log('items updated since', startDateUTC);
}
});

Dyanmic forms from json file in sencha touch

How can I create dynamic form where all the fields are coming from a json file in sencha touch?
(Additional details transferred from "answer")
My json looks like it
{
success: true,
data: [
{xtype: "textfield", title: "label1", name: "textfield1"},
{xtype: "emailfield", title: "label2", name: "textfield2"},
{xtype: "passwordfield", title: "label3", name: "textfield3"},
{xtype: "button", title: "button", name: "button"}
]
}
I want a sepearte controller and a view.
i did it in a single controller file like this
form = Ext.create('MyApp.view.MyDataView');
var test=this;
var ajax = Ext.Ajax.request({
url: 'contacts.json',
method: 'get',
success: function(response)
{
console.log(response);
response = Ext.JSON.decode(response.responseText);
this.hello=response;
console.log(response.data.length);
for (var i = 0; i < response.data.length; i++)
{
form.add({
xtype: response.data[i].xtype,
id:response.data[i].title,
action:response.data[i].title,
label: response.data[i].title,
name: response.data[i].name
});
}
console.log(form.getValues());
form.setLayout();
form.show(document.body);
Ext.Viewport.animateActiveItem(form,{type: 'flip', direction: 'right'});
}
there is some problem i m facing regarding the utton tap event and if multiple buttons are there giving event to them is not yet possible for me ....can anybody help me regarding this ..
Have you tried something yet?
You can just create the form in the file like something like this:
{
xtype: 'form',
items: [ //...
]
}
Then you can load your file in, and decode it into a variable.
Ext.Ajax.request({
url: 'yourform.json',
success: function(response){
var formInJson = response.responseText;
var form = Ext.JSON.decode(formInJson);
//... do something with your form
}
});

Have a button that submits data without AJAX while other buttons submit through AJAX in EXT-JS

i have an EXT.formPanel in which i'd like to have this beahaviour: two buttons should submit through ajax and one shouldn't. How to do this?
This is my code:
form = new Ext.FormPanel({
frame:true,
width:Ext.crl.styles.formWidth,
title: 'Ricerca Atti',
bodyStyle:'padding:5px 5px 0',
defaultType: 'textfield',
formId:'search-form',
keys: [
{ key: [Ext.EventObject.ENTER], handler: function(){
ds.baseParams = form.getForm().getValues();
form.getForm().submit({url:urlRicerca,
waitMsg:'Ricerca in corso…', submitEmptyText: false, method:'GET',params: { start: 0, limit: PAGE_SIZE},
success:function(form,action) {Ext.crl.utils.searchOnSuccess(ds, action, grid); }
});
}
}
],
items: [
ricercaSemplice,
ricercaAvanzata,
{ //This button should submit NOT submit through AJAX!!!
text: 'Esporta Elenco',
disabled:false,
style: 'float:right;',
xtype: 'button',
handler: function() {
ds.baseParams = form.getForm().getValues();
form.getForm().submit({url:urlRicerca+".xls",
waitMsg:'Ricerca in corso…', submitEmptyText: false, method:'GET',params: { enableCsvFilter: "yes", start: 0, limit: PAGE_SIZE},
success:function(form,action) {console.log(action); }
});
}
},{
text: 'Reimposta',
xtype: 'button',
style: 'float:right;margin-right:10px',
disabled: false,
handler: function() {
form.getForm().reset();
//window.location.href = window.location.href;
}
},{
id: 'bottoreCercaRicerca',
name: 'bottoreCercaRicerca',
text: 'Cerca',
xtype: 'button',
style: 'float:right;margin-right:10px',
disabled: false,
handler: function() {
ds.baseParams = form.getForm().getValues();
form.getForm().submit({url:urlRicerca,
waitMsg:'Ricerca in corso…', submitEmptyText: false, method:'GET',params: { start: 0, limit: PAGE_SIZE},
success:function(form,action) {Ext.crl.utils.searchOnSuccess(ds, action, grid); }
});
}
},{
name: 'buttonSwitchRicerca',
xtype: 'button',
style: 'margin-bottom:10px',
text: 'Ricerca Avanzata',
handler: function() {
if(ricercaAvanzata.hidden) {
this.setText('Ricerca Standard');
ricercaAvanzata.show();
}
else {
this.setText('Ricerca Avanzata');
ricercaAvanzata.hide();
}
}
},
DEFAULT_SPACER,
Ext.crl.modalitaLavoro.comboModalitalavoro
]
});
I'v written a comment on where the button should NOT use ajax.
EDIT - i've found a solution, this is an handler that works for not submitting through ajax (actually the fact that opens in a new window is something i want) what i need. Are there any other options?
handler: function() {
query = form.getForm().getValues(true);
query += "&enableCsvFilter=yes";
var url = urlRicerca + ".xls?" + query;
window.open(url);
}
Here is an example :
var ajaxButton1 = new Ext.Button({text:'ajaxButton1 ', handler:ajaxButton1Function});
var ajaxButton2 = new Ext.Button({text:'ajaxButton2 ', handler:ajaxButton2Function});
var noAjaxButton = new Ext.Button({text:'noAjaxButton ', handler:noAjaxButtonFunction});
function ajaxButton1Function(){
Ext.Ajax.Request({
url: 'your url', // you can fix a parameter like this : url?action=anAction1
method: 'POST',
params: {
myField1: myField1.getValue()
// all your params....
},
success: function (result, request){
alert('Succesfully added ' + result.responseText);
},
failure: function (result, request){
alert('Error in server' + result.responseText);
}
});
}
function ajaxButton2Function(){
Ext.Ajax.Request({
url: 'your url', // you can fix a parameter like this : url?action=anAction2
method: 'POST',
params: {
myField1: myField1.getValue()
// all your params....
}
success: function (result, request){
alert('Succesfully added ' + result.responseText);
},
failure: function (result, request){
alert('Error in server' + result.responseText);
}
});
}
function noAjaxButtonFunction(){
form.submit({
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result.msg);
}
});
}

Resources