How to set background image in sencha touch 2 - css

I'm trying to put an image background to my form panel, it doesn't display anything, I'm using the code in this tutoriel:
http://miamicoder.com/2012/adding-a-login-screen-to-a-sencha-touch-application-part-2/
here is my login view:
Ext.define('MyApp2.view.Login', {
extend: 'Ext.form.Panel',
alias: "widget.loginview",
requires: ['Ext.form.FieldSet', 'Ext.form.Password', 'Ext.Label', 'Ext.Img', 'Ext.util.DelayedTask'],
config: {
title: 'Login',
cls:'panelBackground',
// bodyStyle:'background-color:#fff;padding: 10px',
items: [
{
xtype: 'label',
html: 'Login failed. Please enter the correct credentials.',
itemId: 'signInFailedLabel',
hidden: true,
hideAnimation: 'fadeOut',
showAnimation: 'fadeIn',
style: 'color:#990000;margin:5px 0px;'
},
{
xtype: 'fieldset',
title: 'Login Example',
items: [
{
xtype: 'textfield',
placeHolder: 'Username',
itemId: 'userNameTextField',
name: 'userNameTextField',
required: true
},
{
xtype: 'passwordfield',
placeHolder: 'Password',
itemId: 'passwordTextField',
name: 'passwordTextField',
required: true
}
]
},
{
xtype: 'button',
itemId: 'logInButton',
ui: 'action',
padding: '10px',
text: 'Log In'
}
],
listeners: [{
delegate: '#logInButton',
event: 'tap',
fn: 'onLogInButtonTap'
}]
},
onLogInButtonTap: function() {
var me = this,
usernameField = me.down('#userNameTextField'),
passwordField = me.down('#passwordTextField'),
label = me.down('#signInFailedLabel'),
username = usernameField.getValue(),
password = passwordField.getValue();
label.hide();
// Using a delayed task in order to give the hide animation above
// time to finish before executing the next steps.
var task = Ext.create('Ext.util.DelayedTask', function() {
label.setHtml('');
me.fireEvent('signInCommand', me, username, password);
usernameField.setValue('');
passwordField.setValue('');
});
task.delay(500);
},
showSignInFailedMessage: function(message) {
var label = this.down('#signInFailedLabel');
label.setHtml(message);
label.show();
}
});
and my app.css:
.panelBackground
{
background-image: url(http://localhost:8383/MyApp2/resources/images/login.png) !important;
background-repeat: no-repeat !important;
background-size: 100% 100% !important;
}
Ps: I've tried to put it in the index.html, but it seems that nothing is changing, what I'm doing wrong?

The problem is Ext.form.Panel, it renders a scroll container above the background (You can check it in the Chrome Debugger). But i don't know how to disable that.
But when you change it to
Ext.define('MyApp2.view.Login', {
extend: 'Ext.Container',
alias: "widget.loginview",
the code is going to work.
I had a look on the rest of your code, there will be no problem when using a container instead of a form panel.

I am also using same code and tring to set image in background of panel but i am getting blank border on image.
I want to set image in full screen.
Is your images fitted on full screen if yes then please post your code.

Related

Favorite/star/bookmark toggle button in Extjs

How can I have toggle star-shaped button in Extjs, so when the state is 'pressed' it appears like a filled star, and otherwise like an outlined star?
For example, like the star that appears in Google chrome address bar to bookmark the page:
and when it is clicked it changes it appearance to
or it could be a heart that changes to
Or in gmail
For this you can use viewmodel binding to iconCls. Each button has the config: enableToggle: true and it will publishe its pressed-state to the parent-viewModel. Use the bind expression of iconCls: '{theButton.pressed?"fas fa-star":"far fa-star"}' to make it work.
(also integrated FontAwesome5)
Here is the Link to a Sencha-Fiddle
The code:
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.Container', {
renderTo: Ext.getBody(),
layout: 'vbox',
viewModel: {}, // <-- important
items: [{
xtype: 'button',
text: 'Bookmark',
enableToggle: true,
bind: {
iconCls: '{theButton.pressed?"fas fa-star":"far fa-star"}',
},
reference: 'theButton',
handler: function (button) {
if (button.pressed) {
Ext.toast({
html: 'pressed state',
title: 'The button was clicked...',
width: 250,
align: 't'
});
} else {
Ext.toast({
html: 'unpressed state',
title: 'The button was clicked...',
width: 250,
align: 't'
});
};
}
}]
});
}
});
For panel header:
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.panel.Panel', {
title: 'Sample Panel',
tools: [{
glyph: 'xf005#FontAwesome',
pressed: false,
callback: function () {
if (this.pressed) {
this.setGlyph('xf005#FontAwesome'); // star
} else {
this.setGlyph('xf006#FontAwesome'); // star-o
}
this.pressed = !this.pressed;
}
}],
renderTo: Ext.getBody()
});
}
});
And the font awesome style for index.html
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

Unable to change width of a box in css - using extjs framework

I have tried below code in css:
.x-form-field {
margin-left: 10px;
width: 50%;
font: bold 22px;
table-layout: fixed;
width: 10px;
background: grey;
}
Extjs tool bar
And with this I am able to change, font, color, border and margins but not able to change the width of the box.
I want the default width to be 60 px;
I have not worked on css before but i have been struggling with this for past 2 hours. I might be overlooking something.Please help!
You can directly use inputItemWidth config of pagingtoolbar to set the width of input box.
inputItemWidth in pixels of the input field used to display and change the current page number.
In this FIDDLE, I have created a demo using inputItemWidth inside of pagingtoolbar. I hope this will help/guide you to achieve your requirement.
CODE SNIPPET
Ext.application({
name: 'Fiddle',
launch: function () {
// create the Data Store
var store = Ext.create('Ext.data.Store', {
pageSize: 50,
autoLoad:true,
fields: [
'title', {
name: 'replycount',
type: 'int'
}
],
proxy: {
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
type: 'jsonp',
url: '//www.sencha.com/forum/topics-browse-remote.php',
reader: {
root: 'topics',
totalProperty: 'totalCount'
}
}
});
Ext.create('Ext.grid.Panel', {
height: window.innerHeight,
title: 'Demo',
store: store,
loadMask: true,
// grid columns
columns: [{
text: "Topic",
dataIndex: 'title',
flex: 1,
sortable: false
}, {
text: "Replies",
dataIndex: 'replycount',
width: 70,
align: 'right',
sortable: true
}],
// paging bar on the bottom
bbar: Ext.create('Ext.PagingToolbar', {
store: store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display",
inputItemWidth: 60
}),
renderTo: Ext.getBody()
});
}
});

jqGrid add class ui-state-disabled doesn't disable action

I am using jqGrid v 5.1.0 using the Bootstrap style. When I apply ui-state-disabled class to a pager button (add) the button looks disabled but when clicked it still processes the event. In previous version this use to disable the event as well. Using latest FF and IE. Any ideas? Thank you.
Edit - add snippet of code that initializes the grid (child). Notice second line from end where the add button is disabled. The button appears disabled but when clicked the event is executed.
Edit 2 - So after much pain and tears I create two fiddles. One demonstrates proper disabling of the edit button and Two is the same code but using Bootstrap. The edit button is not disabled.
// Water Source grid options...
var source_gridOptions = {
caption: 'Associated Water Source(s)',
data: sourceData,
datatype: 'local',
//url: "", // updated dynamically
//mtype: "GET",
styleUI : 'Bootstrap',
colModel: [
{ label: 'Source ID', name: 'ID', key: true, width: 28 },
{ label: 'Case ID', name: 'WATER_CASE_ID', width: 28, hidden: true },
{ label: 'Intake Name', name: 'INTAKE_SOURCE_NAME', width: 50 },
{ label: 'Intake Type', name: 'INTAKE_SOURCE_TYPE', width: 30 },
{ label: 'Source Type', name: 'SOURCE_TYPE', width: 20 },
{ label: 'Water Type', name: 'WATER_TYPE', width: 20 },
{ label: 'Notes', name: 'NOTES', width: 50 },
{ label: 'Verified', name: 'VERIFIED', width: 25 },
],
viewrecords: true,
height: 'auto',
width: initTabWidth, //dynamically set...
rowNum: 5,
pager: "#sourcePager",
gridComplete: function() {
} // end grid complete event
};
// define CRUD options...
var source_editOptions = {};
var source_addOptions = {};
var source_deleteOptions = {};
// init Water Source grid...
$("#sourceGrid").jqGrid(source_gridOptions).navGrid("#sourcePager",{edit:true,add:true,del:true,search:false},source_editOptions,source_addOptions,source_deleteOptions);
$("#add_sourceGrid").addClass('ui-state-disabled'); // <-- disable button
}); // end grid
Given your demo, I was able to figure it out. You actually need to add the ui-disabled class to work, not just disabled that you've added.
I've modified your fiddle here: http://jsfiddle.net/c6860ev8/16/
You can see in the jqGrid source file which classes are required for bootstrap integration here: https://github.com/tonytomov/jqGrid/blob/7901d7b7da969de1ca98282c60e335e013dc31ee/js/grid.base.js#L1035
Hope this helps!

Processing clicking only when show window

i am click button, when click "ENTER" on keyboard, but i am want processing clicking only when show window ('MyDesktop.Books').But when i am show window, and then close it, when i am click "ENTER", window ('MyDesktop.Books') showing again.
How to do: processing click "ENTER" on keyboard only when show window
Code:
Ext.define('MyDesktop.Books', {
extend: 'MyDesktop.BaseWindow',
id: 'books-win',
title: 'Book',
width: 700,
height: 400,
iconCls: 'small',
layout: 'fit',
items: [
{
xtype: 'bookwrap',
listeners: {
afterrender: function() {
var mapEnterNew = new Ext.KeyMap(document, {
key: 13,
fn: function(e) {
Ext.ComponentQuery.query('bookwrap button[name=createbook]')[0].getEl().dom.click();
}
});
}
}
}
],
});
I think you should either only initialize the window when it's needed for display and remove afterwards, or attach the event in field/form focus and remove it on blur.
I could give a better answer / example if I knew what xtype: "bookwrap" was.
You shouldn't really need to be using getEl().dom.click(), ExtJs can handle all your form submission needs with it's built in components, you can use use refs in your controller to get references to your buttons alot easier.
This code attaches the key event handling on render and removes it again when the window is closed/hidden:
There is also a Fiddle.
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.define('Books', {
extend: 'Ext.window.Window',
id: 'books-win',
title: 'Book',
width: 700,
height: 400,
iconCls: 'small',
layout: 'fit',
items: [{
xtype: 'panel',
html: 'test'
}],
listeners: {
beforehide: function() {
this.mapEnterNew.destroy();
},
afterrender: function() {
this.mapEnterNew = new Ext.KeyMap(document, {
key: 13,
fn: function(e) {
console.log(e);
Ext.ComponentQuery.query('bookwrap button[name=createbook]')[0].getEl().dom.click();
}
});
}
}
});
Ext.create('Books').show();
}
});

ExtJS4 - How to add file upload editor in Grid?

I want to create Grid that has 3 columns. One column is 'textfield' and the other two columns are image which I set editor as 'filefield'. On image column I can display image by using renderer but when it comes to edit or add new image I can't press the browse button to browse image. Here is my code.
var grid = Ext.create('Ext.grid.Panel', {
title: 'Author',
store: Ext.data.StoreManager.lookup('authorStore'),
renderTo: 'authorGrid',
columns: [{
header: 'Name',
dataIndex: 'name',
editor: {
xtype: 'textfield',
}
}, {
header: 'Icon',
dataIndex: 'iconImage',
renderer: function(val) {
return '<img src="' + val + '">';
},
editor: {
xtype: 'filefield',
allowBlank: false,
}
}, {
header: 'Background',
dataIndex: 'background',
renderer: function(val) {
return '<img src="' + val + '">';
},
editor: {
xtype: 'filefield',
allowBlank: false,
}
}],
selModel: Ext.create('Ext.selection.CheckboxModel'),
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})
],
tbar: [{
iconCls: 'icon-add',
text: 'Add',
handler: function() {
// add record
}
}, {
iconCls: 'icon-delete',
text: 'Remove',
handler: function() {
// remove selected records...
}
}, {
iconCls: 'icon-save',
text: 'Save',
handler: function() {
store.save();
}
}]
});
What does it wrong? Can I put 'filefield' editor like this? Is it possible to click save button on grid for save grid data and upload images?
After quick investigation I didn't realized any easy solutions for this issue. In my view EditorGrid isn't supposed to support such type of operations.
And moreover - editor in grid is intended to modify value in corresponding row of the store. With fileupload you operate with files, but as I see in you code you are waiting for a string data in these cells.
What I suggest is replace the fileupload in cells with a popup. When user clicks a cell, you will open popup with fileupload. When they select a file and upload it - you close the popup and reload record in grid's store. Just an idea!

Resources