Is it possible to add buttons in itemTpl in a list or DataView? - sencha-touch

Can anybody put some light on this problem
I would like to add a button to itemTpl in Sencha Touch. The key in {} will be replaced with the values in store. However, is it possible to add buttons in the template as well ?
For example, you list favorite list of music with delete button in each item.
Possible ?

I am not sure whether we can add buttons to itemTpl in Sencha-2 but we can surely add an image to itemTpl and then we can perform various operations (like in your case you want to delete).
Here is the code :-
//demo.js
Ext.define("Stackoverflow.view.demo", {
extend: "Ext.Container",
requires:"Ext.dataview.List",
alias: "widget.demo",
config: {
layout: {
type: 'fit'
},
items: [
{
xtype: "list",
store: "store",
itemId:"samplelist",
loadingText: "Loading Notes...",
emptyText: "<div class=\"notes-list-empty-text\">No notes found.</div>",
onItemDisclosure: true,
itemTpl:"<div class='x-button related-btn' btnType='related' style='border: none; background: url(\"a.png\") no-repeat;'></div>"+
"<div class=\"list-item-title\">{title}</div>"
grouped: true
}
],
listeners:
[
{
delegate: "#samplelist",
event: "disclose",
fn: "onDiscloseTap"
}
]
},
onDiscloseTap: function (list, record, target, index, evt, options) {
this.fireEvent('ondisclosuretap', this, record);
}
});
// Democontrol.js
Ext.define("Stackoverflow.controller.Democontrol", {
extend: "Ext.app.Controller",
config: {
refs: {
// We're going to lookup our views by xtype.
Demo: "demo",
Demo1: "demo list",
},
control: {
Demo: {
ondisclosuretap: "Disclosure",
},
Demo1: {
itemtap:"imagetap"
}
}
},
Disclosure: function (list, record,target,index,e,obj) {
Ext.Msg.alert('','Disclosure Tap');
},
imagetap: function (dataview,index,list,record, tar, obj) {
tappedItem = tar.getTarget('div.x-button');
btntype = tappedItem.getAttribute('btnType');
if(btntype == 'related')
{
Ext.Msg.alert('','Image/Icon Tap');
}
},
// Base Class functions.
launch: function () {
this.callParent(arguments);
},
init: function () {
this.callParent(arguments);
}
});
//app.css
.related-btn
{
width: 100px;
height: 100px;
position: absolute;
bottom: 0.85em;
right: 2.50em;
-webkit-box-shadow: none;
}
Hope this will help.

Related

How can I show the footer buttons in a TinyMCE dialog

I am using TinyMCE 5.6.2 and I have a weird bug with a custom dialog. I have it set to a size of large with a tab panel for the content. I have a header and two buttons setup. When the dialog opens, the buttons are pushed down so that you can just see top few pixels. It looks like some media breakpoint issue because when I resize the window, the buttons become fully visible at a height of 654px and below.
How can I get these buttons to show all the time?
tinymce.PluginManager.add('imageGallery', function (editor, url){
editor.ui.registry.addButton('imageGallery', {
icon: 'gallery',
tooltip: 'Image Gallery',
onAction: function() {
editor.windowManager.open({
title: 'Image Gallery',
size: 'large',
body: {
type: 'tabpanel',
tabs:[
{
name: 'upload',
title: 'Upload',
items: [
{
type: 'dropzone',
name: 'dropzone'
}
]
},
{
name: 'site',
title: 'My Images',
items: [
{
type: 'htmlpanel',
html: '<div id="myImages" class="img-flex-grid"></div>'
}
]
},
{
name: 'shared',
title: 'Shared',
items: [
{
type: 'htmlpanel',
html: '<div id="sharedCategories" style="float: left; min-width: 150px; background-color: lightgray; font-size: 14px; color: rgba(34,47,62,.7);"></div><div id="sharedImages" class="img-flex-grid" style="float: right; width: 900px"></div>'
}
]
},
],
},
buttons: [
{
type: 'submit',
text: 'Select',
name: 'select',
disabled: true,
primary: true,
},
{
type: 'cancel',
text: 'Close'
}],
onChange: function(dialogInstance, details) {
handleInputChange(dialogInstance, details);
},
onSubmit: function() {
handleSubmit();
},
onTabChange: function(dialogInstance, details) {
handleMainTabChange(dialogInstance, details.newTabName)
}
});
}
});
}
If anyone else is having this issue, I had to override a CSS class. Because I am accessing TinyMCE via a CDN, I do not see a way to create a custom skin or theme. This is the code that I added to my CSS file.
.tox-dialog--width-lg {
min-height: 650px !important;
height: auto !important;
}

Defect Suite Popover

Is there a way to implement a Defect Suite Popover within a Rally Grid that allows for viewing Defect Suites associated with a Defect? Currently, only the count of Defect Suites for a given Defect seems available.
This one took a little bit of tinkering, but here's what I came up with. I included the full app because there are a few moving parts. Basically this setup mirrors the way the other existing popovers are built (Defects, Tasks, etc.)
First we define a popover. I borrowed code from the TaskPopover as a starting point and then updated the parentProperty and childField configs near the bottom and changed the columns to be shown.
Next we define a status template to render the defect suite count in the grid. Again, I borrowed code from the TaskStatusTemplate as a starting point and just tweaked it a little bit to show the right data. There is some css at the bottom of the app to style it as well.
Finally, in the sample app included I add a grid of defects that all contain defect suites to test it. There are two little overrides at the beginning of the launch method to completely wire up the popover.
Hope that gets you started!
<!DOCTYPE html>
<html>
<head>
<title>DefectSuitePopover</title>
<script type="text/javascript" src="/apps/2.0/sdk.js"></script>
<script type="text/javascript">
Rally.onReady(function () {
//
//Define the popover
//
Ext.define('DefectSuitePopover', {
alias: 'widget.defectsuitepopover',
extend: 'Rally.ui.popover.ListViewPopover',
title: 'Defect Suites',
titleIconCls: 'icon-defect-suite',
width: 700,
constructor: function (config) {
config.listViewConfig = Ext.merge({
gridConfig: {
addNewConfig: {},
columnCfgs: [
{
dataIndex: 'FormattedID',
width: 90
},
{
dataIndex: 'Name',
flex: 1
},
{
dataIndex: 'Owner',
width: 90
},
{
dataIndex: 'ScheduleState',
width: 55
}
],
storeConfig: {
context: config.context
}
},
model: Ext.identityFn('DefectSuite'),
parentProperty: 'Defects',
childField: 'DefectSuites'
}, config.listViewConfig);
this.callParent(arguments);
}
});
//
//Define the status template for the grid to launch the popover
//
Ext.define('DefectSuitesStatusTemplate', {
extend: 'Rally.ui.renderer.template.status.StatusTemplate',
inheritableStatics: {
onClick: function(event, ref) {
Rally.ui.renderer.template.status.StatusTemplate.onClick(event, ref, {
field: 'DefectSuite',
target: event.target,
targetSelector: 'a.id-' + Rally.util.Ref.getOidFromRef(ref)
});
}
},
constructor: function() {
this.callParent([
'<tpl if="this._getCount(values) > 0">',
'<a class="defect-suites-count id-{[values.ObjectID]}" onclick="{[this._getOnClick(values)]}">',
'{[this._getCount(values)]}',
'</a>',
'</tpl>'
]);
},
_getCount: function (recordData) {
return recordData.DefectSuites.Count;
},
_getOnClick: function(recordData) {
return 'DefectSuitesStatusTemplate.onClick(event, \'' + recordData._ref + '\'); return false;';
}
});
//
//Define the app
//
Ext.define('DefectSuitePopoverApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
//Add the new status template
Rally.ui.renderer.RendererFactory.fieldTemplates.defectsuites = function() {
return Ext.create('DefectSuitesStatusTemplate');
};
//Register the popover
Rally.ui.popover.PopoverFactory.popovers.DefectSuite = function(config) {
return Ext.create('DefectSuitePopover', config);
};
//Add grid
this.add({
xtype: 'rallygrid',
columnCfgs: [
'FormattedID',
'Name',
'Owner',
{
dataIndex: 'DefectSuites',
align: 'center'
},
'Tasks',
'State'
],
context: this.getContext(),
enableEditing: false,
showRowActionsColumn: false,
storeConfig: {
model: 'defect',
filters: [{
property: 'DefectSuites.ObjectID',
operator: '!=',
value: null
}]
}
});
}
});
Rally.launchApp('DefectSuitePopoverApp', {
name:"DefectSuitePopover",
parentRepos:""
});
});
</script>
<style type="text/css">
.app a.defect-suites-count {
cursor: pointer;
color: #337ec6;
}
</style>
</head>
<body>
</body>
</html>

How to use the html id in sencha touch

I am new to sencha touch. I am creating a app in which i am using a html . When that span is clicked a function in controller should be called . I have attached the view and controller with this question.
View
Ext.define('SlideNav.view.Viewport', {
extend: 'Ext.Container',
xtype: 'app_viewport',
requires: [
'Ext.TitleBar'
],
config: {
fullscreen: true,
layout: 'hbox',
items : [
{
docked: 'top',
xtype: 'panel',
height: 40,
style:'background:white ;height:40px;color:black',
items:[
{
html:'<div><span style="padding:10px;position:absolute" id="TopNews">Top News</span><span style="padding:13px;position:absolute;right:10px;font-size:12px">MORE</span></div>'
}
],
listeners: {
initialize:function(){
this.fireEvent('onPopulateDashBoardData', this);
}
/* tap: {
fn: function(event, el){ console.log("tapped!");
this.fireEvent('onPopulateDashBoardData', this);
},
element: 'element',
delegate: '#TopNews'
}*/
}
},
{
xtype : 'main',
cls: 'slide',
// Needed to fit the whole content
width: '100%'
}, {
xtype : 'navigation',
width : 250
}]
}
});
controller.js
Ext.define('SlideNav.controller.App',{
extend: 'Ext.app.Controller',
config:{
refs:{
app_viewport: 'app_viewport',
main : 'main',
navigation : 'navigation',
navBtn : 'button[name="nav_btn"]',
},
control : {
app_viewport:{
onPopulateDashBoardData:'toggleNav'
},
navBtn : {
tap : 'toggleNav'
},
navigation : {
itemtap : function(list, index, target, record){
this.toggleNav();
console.log(record);
alert(record._data.title);
}
}
}
},
/**
* Toggle the slide navogation view
*/
toggleNav : function(){
var me = this,
mainEl = me.getMain().element;
console.log('hai');
if (mainEl.hasCls('out')) {
mainEl.removeCls('out').addCls('in');
me.getMain().setMasked(false);
} else {
mainEl.removeCls('in').addCls('out');
me.getMain().setMasked(true);
}
}
});
In the above question , i want to click a text with id TopNews from and want to call a function toggleNav in controller. I tried to fire a event with the name onPopulateDashBoardData and tried to use that event in the controller. But it is also not working . What should you know.
The way you are referring the text is wrong.
Do this:-
items:[{
name: 'top_news', // add this name for referring
html:'<div><span style="padding:10px;position:absolute" id="TopNews">Top News</span><span style="padding:13px;position:absolute;right:10px;font-size:12px">MORE</span></div>'
}]
Controller:-
refs:{
menu: container[name='top_news']
},
control : {
menu : {
initialize: function(container) {
container.element.on({
tap: 'toggleNav',
scope: this,
delegate: '#TopNews'
});
}
}
}

How To Reference a container from a button on same level in ExtJS

I've got a structure like below.
I can reference (from the button handler) with up.down my component but I'm wondering if there is a more correct way to do this.
Ext.application({
name: 'MyApp',
launch: function () {
Ext.create('Ext.container.Viewport', {
items: [
{
tpl: 'Name: {first} {last}',
data: {
first: 'Peter',
last: 'Kellner'
},
padding: 20,
width: 200,
height: 200,
style: {
border: '2px solid red'
},
resizable: true,
itemId: 'myComponentItemId',
listener: {
resize: {
fn: function(component, width, height) {
console.log("w/h:" + width + " " + height);
}
}
}
},{
xtype: 'button',
text: "Disable",
handler: function () {
debugger;
this.up().down('#myComponentItemId').disable();
}
}
]
});
}
});
It is correct to use .up.down for what you are trying to do. You could use something like :
.up('form').down('button#login')
What you use in your code, on the other hand is not correct : this.up().down('#myComponentItemId'). You must pass a component selector as argument to .up().
Alternatives to .up.down are .nextSibling and .previousSibling. Similar, but more general there are also .nextNode and .previousNode.

tap event not working in view

Please check the code below, what I am doing wrong? I want to output to console when tap event on body.
Ext.define('iApp.view.LoginView', {
extend: 'Ext.Panel',
xtype: 'loginViewPanel',
config: {
style: "background-color: #3f3f3f;",
html: 'hello world',
listeners: {
el: {
tap: function() {
console.log('tapped');
}
}
}
}
});
no output to console...
You are using an old version of adding an element listener.
If you use the compat version fo Sencha Touch 2, it should give you a warning in the console like this:
So your code should look something like this:
Ext.define('iApp.view.LoginView', {
extend: 'Ext.Panel',
xtype: 'loginViewPanel',
config: {
style: "background-color: #3f3f3f;",
html: 'hello world',
listeners: {
tap: {
element: 'element',
fn: function() {
console.log('tapped');
}
}
}
}
});
You can find out more information about the changes on the Sencha Forums.
Update
If you want to delegate to a child of the item, you must still target element, and then within your function check if the tapped element is the one you want:
var component = Ext.Viewport.add({
width: 300,
height: 300,
style: 'background: red',
html: 'Tap me<div id="test" style="background:blue;">Only this will alert</div>',
listeners: {
tap: {
element: 'element',
fn: function(e) {
var element = Ext.get(e.target);
if (element.id == "test") {
alert('tap!');
}
}
}
}
});
If you want to select an element by class or id, it's cleaner to use the delegate option:
var component = Ext.Viewport.add({
width: 300,
height: 300,
style: 'background: red',
html: 'Tap me<div id="test" style="background:blue;">Only this will alert</div>',
listeners: {
tap: {
element: 'element',
delegate: '#test',
fn: function(e) {
alert('Element with id "test" was tapped!');
}
}
}
});
Ext.define('app.view.Card', {
config : {
layout : 'card',
items : [{
xtype : 'panel',
docked : 'top',
html : "<img width='320px' id='image1' src='images/im.jpg'/>",
listeners : {
touchstart : {
element : 'element',
fn : function() {
console.log('tapped')
}
}
}
}]
},
initialize : function() {
// if recording/handling the event in the controller.
this.relayEvents(this.element, ['tap']);
}
});
A simpler and cleaner way of getting Tappable Panels
Ext.define('My.component.TappablePanel', {
extend: 'Ext.Panel',
initialize: function () {
this.element.on('tap', function(){
this.tap();
}, this);
},
tap: function() {
console.log('I heard the tap!');
}
});
And it can be overridden in child classes like so...
Ext.define('My.view.TestPanel', {
extend: 'My.component.TappablePanel',
config: {
html: 'Tap this panel',
style: 'background-color: #5E99CC'
},
tap: function() {
console.log('I handled the tap');
}
});