/* ExtJS code to create a form */
var customerEditMainFormParent = new Ext.FormPanel({
labelAlign: 'top',
header:false,
style: "height: 200px;",
border:false,
renderTo: 'updateCustomer',
id: "customer-form2",
name: "customer-form2",
fileUpload:true,
isUpload: true,
enctype:'multipart/form-data',
url: Ext.SERVER_URL + 'save_file_data',
items: [
{
xtype: 'fileuploadfield',
id: 'filedata',
emptyText: 'Select a document to upload...',
fieldLabel: 'File',
buttonText: 'Browse'
}
]
)};
/* Grails code */
if(params.containsKey("filedata") && bankAccountDetails != null) {
try {
String path = System.getProperty("java.io.tmpdir");
/* Temporary directory */
CommonsMultipartFile uploadFile = request.getFile("filedata");
println uploadFile.getOriginalFilename();
println uploadFile.getContentType();
println uploadFile.getStorageDescription();
uploadFile.transferTo(new File(path+"a.png"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
Showing posts with label ExtJs. Show all posts
Showing posts with label ExtJs. Show all posts
Sunday, August 11, 2013
File upload using ExtJS and Grails
ExtJS add checkbox group to a panel on fly
/* Add a panel to parent panel as item */
{
xtype: 'panel',
id: "paymentMethod",
fieldLabel: 'Preferred Payment Method'
}
/* Bind 'load' event on store that loads data as JSON */
var paymentstore = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: Ext.SERVER_URL + 'get_data',
method: 'post'
}),
listeners :{
load:function() {
var testArray = new Array();
for(var i=0; i<records.length; i++) {
testArray.push({
id: "some_id_" + records[i].data.id,
checked: true, /* or false */
name: "payment_method[" + records[i].data.id + "]",
boxLabel: records[i].data.name,
listeners:{
check:function (clickedObject, isChecked){
console.log(
clickedObject
);
console.log(
isChecked
);
console.log("Check box check status changed.");
var group = Ext.getCmp ("
payment_group
");
var length = group.items.getCount ();
var isCheck = group.items.items [0]. checked;
}
}
});
}
var myCheckboxgroup = new Ext.form.CheckboxGroup({
id:'payment_group',
fieldLabel: 'Checkboxes',
boxLabel:'State',
columns: 1,
items:testArray //created in previous snippet.
});
Ext.getCmp("paymentMethod").add(myCheckboxgroup);
Ext.getCmp("paymentMethod").doLayout();
}
},
fields: ['id', 'name', "description"],
totalProperty: 'totalCount',
root: 'data'
});
/* Load store */
paymentstore.load({
params: {
start: 0
}
});
Thursday, August 8, 2013
Extjs combobox:How to set user selected value as the default selected value
/* Date store */
var dataStore = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: Ext.SERVER_URL + 'get_data',
method: 'post'
}),
listeners :{
load:function() {
/**
/* The code block at the end labeled
/* 'And select a value after load store' can be written here.
*/
}
},
fields: ['id', 'name'],
totalProperty: 'totalCount',
root: 'data'
});
/* Suppose data returned as */
{totalCount: 2, data: [{"id":1,"name":"First Item"},{"id":2,"name":"Second Item"}] }
/* Combobox initialize */
{
xtype: 'combo',
id: "domId",
fieldLabel: 'Data Name',
hiddenName: 'cb_data',
store: dataStore,
displayField: 'name',
labelSeparator :'',
valueField: 'id',
typeAhead: true,
autoSelect: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus: true,
allowBlank: true,
blankText: 'Select status',
editable: false
}
/* And select a value after load store */
var combo = Ext.getCmp("domId");
combo.getStore().on(
"load",function() {
var value = 2;
/* Set your value to select in combobox */
/* This will select with id = 2 and label = 'Second Item'.
if(value == 0) { /* Default selection */
var recordSelected = combo.getStore().getAt(0);
combo.setValue(recordSelected.get('id'));
} else {
combo.setValue(value);
}
},
this,
{
single: true
}
);
Monday, July 22, 2013
Get form values from extjs form as urlencode
var values = Ext.getCmp('FORM_NAME').getForm().getValues(true);
OR
var values = Ext.getCmp('FORM_NAME').getForm().getValues(false);
OR
var values = Ext.getCmp('FORM_NAME').getForm().getValues(false);
Sunday, May 5, 2013
ExtJS: HtmlEditor command list
The following list of commands is presented in alphabetical order. The commands may be mixed case or whatever makes your code more readable.
command | value | explanation / behavior |
backcolor | ???? | This command will set the background color of the document. |
bold | none | If there is no selection, the insertion
point will set bold for subsequently typed characters. If there is a selection and all of the characters are already bold, the bold will be removed. Otherwise, all selected characters will become bold. |
contentReadOnly | true false |
This command will make the editor readonly (true) or editable (false). Anticipated usage is for temporarily disabling input while something else is occurring elsewhere in the web page. |
copy | none | If there is a selection, this command will copy the selection
to the clipboard. If there isn't a selection, nothing will happen. note: this command won't work without setting a pref or using signed JS. See: http://www.mozilla.org/editor/midasdemo/securityprefs.html note: the shortcut key will automatically trigger this command (typically accel-C) with or without the signed JS or any code on the page to handle it. |
createlink | url (href) | This command will not do anything if no selection is made. If there is a selection, a link will be inserted around the selection with the url parameter as the href of the link. |
cut | none | If there is a selection, this command will copy the selection
to the clipboard and remove the selection from the edit control.
If there isn't a selection, nothing will happen. note: this command won't work without setting a pref or using signed JS. See: http://www.mozilla.org/editor/midasdemo/securityprefs.html note: the shortcut key will automatically trigger this command (typically accel-X) with or without the signed JS or any code on the page to handle it. |
decreasefontsize | none | This command will add a <small> tag around selection or at insertion point. |
delete | none | This command will delete all text and objects that are selected. |
fontname | ???? | This command will set the fontface for a selection or at the insertion point if there is no selection. |
fontsize | ???? | This command will set the fontsize for a selection or at the insertion point if there is no selection. |
forecolor | ???? | This command will set the text color of the selection or at the insertion point. |
formatblock | <h1> <h2> <h3> <h4> <h5> <h6> <pre> <address> <p> p [this list may not be complete] |
|
heading | <h1> <h2> <h3> <h4> <h5> <h6> |
|
hilitecolor | ???? | This command will set the hilite color of the selection or at the insertion point. It only works with usecss enabled. |
increasefontsize | none | This command will add a <big> tag around selection or at insertion point. |
indent | none | Indent the block where the caret is located. |
inserthorizontalrule | none | This command will insert a horizontal rule
(line) at the insertion point. Does it delete the selection? |
inserthtml | valid html string | This command will insert the given html into the <body> in place of the current selection or at the caret location. |
insertimage | url (src) | This command will insert an image (referenced by
url) at the insertion point. Does it delete the selection? |
insertorderedlist | none | |
insertunorderedlist | none | |
insertparagraph | none | |
italic | none | If there is no selection, the insertion
point will set italic for subsequently typed characters. If there is a selection and all of the characters are already italic, the italic will be removed. Otherwise, all selected characters will become italic. |
justifycenter | none | |
justifyfull | none | |
justifyleft | none | |
justifyright | none | |
outdent | none | Outdent the block where the caret is located. If the
block is not indented prior to calling outdent, nothing will happen. note: is an error thrown if no outdenting is done? |
paste | none | This command will paste the contents of the clipboard at the
location of the caret. If there is a selection, it will be deleted
prior to the insertion of the clipboard's contents. note: this command won't work without setting a pref or using signed JS. user_pref("capability.policy.policynames",
"allowclipboard");
user_pref("capability.policy.allowclipboard.Clipboard.paste",
"allAccess"); See: http://www.mozilla.org/editor/midasdemo/securityprefs.html note: the shortcut key will automatically trigger this command (typically accel-V) with or without the signed JS or any code on the page to handle it. |
redo | none | This command will redo the previous undo action. If undo
was not the most recent action, this command will have no effect. note: the shortcut key will automatically trigger this command (typically accel-shift-Z) |
removeformat | none | |
selectall | none | This command will select all of the contents within the
editable area. note: the shortcut key will automatically trigger this command (typically accel-A) |
strikethrough | none | If there is no selection, the insertion point
will set strikethrough for subsequently typed characters. If there is a selection and all of the characters are already striked, the strikethrough will be removed. Otherwise, all selected characters will have a line drawn through them. |
styleWithCSS | true false |
This command is used for toggling the format of generated content. By default (at least today), this is true. An example of the differences is that the "bold" command will generate <b> if the styleWithCSS command is false and generate css style attribute if the styleWithCSS command is true. |
subscript | none | If there is no selection, the insertion point
will set subscript for subsequently typed characters. If there is a selection and all of the characters are already subscripted, the subscript will be removed. Otherwise, all selected characters will be drawn slightly lower than normal text. |
superscript | none | If there is no selection, the insertion point
will set superscript for subsequently typed characters. If there is a selection and all of the characters are already superscripted, the superscript will be removed. Otherwise, all selected characters will be drawn slightly higher than normal text. |
underline | none | If there is no selection, the insertion
point will set underline for subsequently typed characters. If there is a selection and all of the characters are already underlined, the underline will be removed. Otherwise, all selected characters will become underlined. |
undo | none | This command will undo the previous action. If no action
has occurred in the document, then this command will have no effect. note: the shortcut key will automatically trigger this command (typically accel-Z) |
unlink | none |
ExtJS: Add font family custom drop down in toolbar
ExtJS has some command to make it easy. ExtJS has some font names, but if you want more font then you
shoud make your own component. The following component override the existing font names with some
font name you provide, such I provide extra font name "Candara" here.
Some command in ExtJS HtmlEditor:
shoud make your own component. The following component override the existing font names with some
font name you provide, such I provide extra font name "Candara" here.
Some command in ExtJS HtmlEditor:
this.execCmd('InsertHTML',' ');
this.execCmd('InsertText','\t');
this.execCmd('useCSS', true);
this.execCmd('styleWithCSS', false);
doc = this.getDoc();
doc.queryCommandValue('FontName')
;doc.queryCommandState('bold');
doc.queryCommandState('italic');
doc.queryCommandState('underline');
doc.queryCommandState('justifyleft');
doc.queryCommandState('justifycenter');
doc.queryCommandState('insertorderedlist');
doc.queryCommandState('insertunorderedlist');
this.insertAtCursor('<hr/>');
r = doc.selection.createRange();
r.collapse(true);
r.pasteHTML(' ');
this.deferFocus();
Ext.form.HtmlEditor.Font = Ext.extend(Ext.util.Observable, { init: function(cmp){ this.cmp = cmp; this.cmp.on('render', this.onRender, this); }, // private onRender: function(){ var cmp = this.cmp; var fonts = function(){ var fnts = []; Ext.each(cmp.fontFamilies, function(itm){ fnts.push([itm.toLowerCase(),itm]); }); fnts.push(["candara", "Candara"]); return fnts; }(); var btn = this.cmp.getToolbar().addItem({ xtype: 'combo', displayField: 'display', valueField: 'value', name: 'fontfamily', forceSelection: true, selectOnFocus: true, selected: "Candara", editable: false, mode: 'local', triggerAction: 'all', width: 80, emptyText: 'Font', tpl: '<tpl for="."><div class="x-combo-list-item" style="font-family:{value};">{display}</div></tpl>', store: { xtype: 'arraystore', autoDestroy: true, fields: ['value','display'], data: fonts }, listeners: { 'select': function(combo,rec){ cmp.relayCmd('FontName', rec.get('value')); }, scope: cmp } }); } });
ExtJS: add button to htmleditor
I am using ExtJS and I have a htmleditor in my form. I would like to
add a custom button to that element (for example after all other buttons
like alignments, font weights, ...). This button should basically
insert a standard template in the htmlfield. Being this template html,
the behaviour of the button should be like this
But I really recommend you to see the project HtmlEditor.Plugins at google code. There you can find a lot more about adding custom buttons, for instance, how to enable/disable the buttons when something is selected, put separators, etc.
https://docs.google.com/file/d/0B5nZNPW48dpFb0hJVmpVUEphZGc/edit?usp=sharing
- Switch to HTML mode (like when pressing Source button)
- Insert something
- Switch back to WYSIWYG mode (like when pressing the Source button again)
Ext.ns('Ext.ux.form.HtmlEditor'); Ext.ux.form.HtmlEditor.HR = Ext.extend(Ext.util.Observable, { init: function(cmp){ this.cmp = cmp; this.cmp.on('render', this.onRender, this); }, onRender: function(){ this.cmp.getToolbar().addButton([{ iconCls: 'x-edit-custom', //your iconCls here handler: function(){ this.cmp.insertAtCursor('<hr>'); }, scope: this, tooltip: 'horizontal ruler', overflowText: 'horizontal ruler' }]); } }); var w = new Ext.Window({ width: 550, layout: 'fit', items: [{ xtype: 'htmleditor', plugins: [new Ext.ux.form.HtmlEditor.HR()] }] }); w.show();
But I really recommend you to see the project HtmlEditor.Plugins at google code. There you can find a lot more about adding custom buttons, for instance, how to enable/disable the buttons when something is selected, put separators, etc.
https://docs.google.com/file/d/0B5nZNPW48dpFb0hJVmpVUEphZGc/edit?usp=sharing
Thursday, November 29, 2012
ExtJS ComboBox with local store and change action listener.
new Ext.form.ComboBox({
fieldLabel: '',
id: 'searchtypeforcontacts',
name: 'searchtype',
x:200,
labelSeparator :'',
editable: false,
store: new Ext.data.SimpleStore({
fields: ['id', 'header'],
data: [
['id', 'Contact Id'],
['first_name', 'Given Name'],
['email', 'Email'],
['country', 'Country'],
['state', 'State'],
['suburb_city', 'Suburb/City'],
['post_zip_code', 'Post/Zip Code']
]
}),
displayField: 'header',
valueField: 'id',
emptyText:'Search Contacts',
typeAhead: true,
mode: 'local',
anchor: '40%',
triggerAction: 'all',
allowBlank: false,
selectOnFocus: true,
blankText: 'Select search type',
listeners:{
'select':function() {
if (this.value == 'status') {
//statusCombo.show();
searchText.hide();
$(".customerSearch").css({'margin-left':'210px','width':'auto'});
} else {
//statusCombo.hide();
searchText.show();
$(".customerSearch").removeAttr("style").css("width:auto;");
}
}
}
})
fieldLabel: '',
id: 'searchtypeforcontacts',
name: 'searchtype',
x:200,
labelSeparator :'',
editable: false,
store: new Ext.data.SimpleStore({
fields: ['id', 'header'],
data: [
['id', 'Contact Id'],
['first_name', 'Given Name'],
['email', 'Email'],
['country', 'Country'],
['state', 'State'],
['suburb_city', 'Suburb/City'],
['post_zip_code', 'Post/Zip Code']
]
}),
displayField: 'header',
valueField: 'id',
emptyText:'Search Contacts',
typeAhead: true,
mode: 'local',
anchor: '40%',
triggerAction: 'all',
allowBlank: false,
selectOnFocus: true,
blankText: 'Select search type',
listeners:{
'select':function() {
if (this.value == 'status') {
//statusCombo.show();
searchText.hide();
$(".customerSearch").css({'margin-left':'210px','width':'auto'});
} else {
//statusCombo.hide();
searchText.show();
$(".customerSearch").removeAttr("style").css("width:auto;");
}
}
}
})
Subscribe to:
Posts (Atom)