📄 samplescripts.debug.js
字号:
// SampleScripts.js
//
Type.createNamespace('SampleScripts.core');
////////////////////////////////////////////////////////////////////////////////
// SampleScripts.core.TemplateScript
SampleScripts.core.TemplateScript = function SampleScripts_core_TemplateScript() {
}
SampleScripts.core.TemplateScript.main = function SampleScripts_core_TemplateScript$main(args) {
ExtClass.onReady(Delegate.create(null, function() {
new SampleScripts.core.TemplateScript().init();
}));
}
SampleScripts.core.TemplateScript.prototype = {
_p1: null,
_p2: null,
init: function SampleScripts_core_TemplateScript$init() {
var data = { name: 'Jack Slocum', company: 'Ext JS, LLC', address: '4 Red Bulls Drive', city: 'Cleveland', state: 'Ohio', zip: '44102', kids: [ { name: 'Sara Grace', age: 3 }, { name: 'Zachary', age: 2 }, { name: 'John James', age: 0 } ] };
this._p1 = new Ext.Panel(new Ext.PanelConfig().title('Basic Template').width(300).html('<p><i>Apply the template to see results here</i></p>').tbar([ new Ext.Toolbar.ButtonConfig().text('Apply Template').handler(Delegate.create(this, function() {
var tpl = new Ext.Template('<p>Name: {name}</p>\r\n\t\t\t\t\t\t\t\t\t\t\t<p>Company: {company}</p>\r\n\t\t\t\t\t\t\t\t\t\t\t<p>Location: {city}, {state}</p>');
var body = this._p1.body;
tpl.overwrite(body, data);
body.highlight('#c3daf9', { block: true });
})).toDictionary() ]).renderTo(document.body).toDictionary());
this._p2 = new Ext.Panel(new Ext.PanelConfig().title('XTemplate').width(300).html('<p><i>Apply the template to see results here</i></p>').tbar([ new Ext.Toolbar.ButtonConfig().text('Apply Template').handler(Delegate.create(this, function() {
var tpl = new Ext.XTemplate('<p>Name: {name}</p>\r\n\t\t\t\t\t\t\t\t\t\t\t<p>Company: {company}</p>\r\n\t\t\t\t\t\t\t\t\t\t\t<p>Location: {city}, {state}</p>\r\n\t\t\t\t\t\t\t\t\t\t\t<p>Kids: \r\n\t\t\t\t\t\t\t\t\t\t\t<tpl for=\"kids\" if=\"name==\'Jack Slocum\'\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t<tpl if=\"age > 1\"><p>{#}. {parent.name}\'s kid - {name}</p></tpl>\r\n\t\t\t\t\t\t\t\t\t\t\t</tpl></p>');
var body = this._p2.body;
tpl.overwrite(body, data);
body.highlight('#c3daf9', { block: true });
})).toDictionary() ]).renderTo(document.body).toDictionary());
}
}
Type.createNamespace('SampleScripts.menu');
////////////////////////////////////////////////////////////////////////////////
// SampleScripts.menu.State
SampleScripts.menu.State = function SampleScripts_menu_State(_abbr, _state) {
this.abbr = _abbr;
this.state = _state;
}
SampleScripts.menu.State.prototype = {
abbr: null,
state: null
}
////////////////////////////////////////////////////////////////////////////////
// SampleScripts.menu.ComboScript
SampleScripts.menu.ComboScript = function SampleScripts_menu_ComboScript() {
this._states = [ [ 'AL', 'Alabama' ], [ 'AK', 'Alaska' ], [ 'AZ', 'Arizona' ], [ 'AR', 'Arkansas' ], [ 'CA', 'California' ], [ 'CO', 'Colorado' ], [ 'CT', 'Connecticut' ], [ 'DE', 'Delaware' ], [ 'DC', 'District of Columbia' ], [ 'FL', 'Florida' ], [ 'GA', 'Georgia' ], [ 'HI', 'Hawaii' ], [ 'ID', 'Idaho' ], [ 'IL', 'Illinois' ], [ 'IN', 'Indiana' ], [ 'IA', 'Iowa' ], [ 'KS', 'Kansas' ], [ 'KY', 'Kentucky' ], [ 'LA', 'Louisiana' ], [ 'ME', 'Maine' ], [ 'MD', 'Maryland' ], [ 'MA', 'Massachusetts' ], [ 'MI', 'Michigan' ], [ 'MN', 'Minnesota' ], [ 'MS', 'Mississippi' ], [ 'MO', 'Missouri' ], [ 'MT', 'Montana' ], [ 'NE', 'Nebraska' ], [ 'NV', 'Nevada' ], [ 'NH', 'New Hampshire' ], [ 'NJ', 'New Jersey' ], [ 'NM', 'New Mexico' ], [ 'NY', 'New York' ], [ 'NC', 'North Carolina' ], [ 'ND', 'North Dakota' ], [ 'OH', 'Ohio' ], [ 'OK', 'Oklahoma' ], [ 'OR', 'Oregon' ], [ 'PA', 'Pennsylvania' ], [ 'RI', 'Rhode Island' ], [ 'SC', 'South Carolina' ], [ 'SD', 'South Dakota' ], [ 'TN', 'Tennessee' ], [ 'TX', 'Texas' ], [ 'UT', 'Utah' ], [ 'VT', 'Vermont' ], [ 'VA', 'Virginia' ], [ 'WA', 'Washington' ], [ 'WV', 'West Virginia' ], [ 'WI', 'Wisconsin' ], [ 'WY', 'Wyoming' ] ];
}
SampleScripts.menu.ComboScript.main = function SampleScripts_menu_ComboScript$main(args) {
ExtClass.onReady(Delegate.create(null, function() {
new SampleScripts.menu.ComboScript().init();
}));
}
SampleScripts.menu.ComboScript.prototype = {
init: function SampleScripts_menu_ComboScript$init() {
var store = new Ext.data.SimpleStore(new Ext.data.SimpleStoreConfig().fields([ 'abbr', 'state' ]).data(this._states).toDictionary());
new Ext.form.ComboBox(new Ext.form.ComboBoxConfig().store(store).displayField('state').typeAhead(true).mode('local').triggerAction('all').emptyText('Select a state...').selectOnFocus(true).applyTo('local-states').toDictionary());
new Ext.form.ComboBox(new Ext.form.ComboBoxConfig().typeAhead(true).triggerAction('all').transform('state').width(135).forceSelection(true).toDictionary());
}
}
////////////////////////////////////////////////////////////////////////////////
// SampleScripts.menu.CustomScript
SampleScripts.menu.CustomScript = function SampleScripts_menu_CustomScript() {
}
SampleScripts.menu.CustomScript.main = function SampleScripts_menu_CustomScript$main(args) {
ExtClass.onReady(Delegate.create(null, function() {
new SampleScripts.menu.CustomScript().init();
}));
}
SampleScripts.menu.CustomScript.prototype = {
init: function SampleScripts_menu_CustomScript$init() {
var ds = new Ext.data.Store(new Ext.data.StoreConfig().custom('proxy', new Ext.data.ScriptTagProxy(new Ext.data.ScriptTagProxyConfig().url('http://extjs.com/forum/topics-remote.php').toDictionary())).reader(new Ext.data.JsonReader(new Ext.data.JsonReaderConfig().root('topics').totalProperty('totalCount').id('post_id').toDictionary(), [ { name: 'postId', mapping: 'post_id' }, { name: 'title', mapping: 'topic_title' }, { name: 'topicId', mapping: 'topic_id' }, { name: 'author', mapping: 'author' }, { name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp' }, { name: 'excerpt', mapping: 'post_text' } ])).baseParams({ limit: 20, forumId: 4 }).toDictionary());
var resultTpl = new Ext.XTemplate('<tpl for=\".\">\r\n\t\t\t\t<div class=\"search-item\">\r\n\t\t\t\t\t<h3><span>{lastPost:date(\"M j, Y\")}<br />by {author}</span>\r\n\t\t\t\t\t<a href=\"http://extjs.com/forum/showthread.php?t={topicId}&p={postId}\" target=\"_blank\">{title}</a></h3>\r\n\t\t\t\t\t<p>{excerpt}</p>\r\n\t\t\t\t</div></tpl>');
new Ext.Panel(new Ext.PanelConfig().applyTo('search-panel').title('Forum Search').height(300).autoScroll(true).items(new Ext.DataView(new Ext.DataViewConfig().tpl(resultTpl).store(ds).itemSelector('div.search-item').toDictionary())).bbar(new Ext.PagingToolbar(new Ext.PagingToolbarConfig().store(ds).pageSize(20).displayInfo(true).displayMsg('Topics {0} - {1} of {2}').emptyMsg('No topics to display').toDictionary())).toDictionary());
ds.load({ params: { start: 0, limit: 20, forumId: 4 } });
}
}
////////////////////////////////////////////////////////////////////////////////
// SampleScripts.menu.ActionsScript
SampleScripts.menu.ActionsScript = function SampleScripts_menu_ActionsScript() {
}
SampleScripts.menu.ActionsScript.main = function SampleScripts_menu_ActionsScript$main(args) {
ExtClass.onReady(Delegate.create(null, function() {
new SampleScripts.menu.ActionsScript().init();
}));
}
SampleScripts.menu.ActionsScript.prototype = {
init: function SampleScripts_menu_ActionsScript$init() {
var action = new Ext.Action(new Ext.ActionConfig().text('Action 1').handler(Delegate.create(this, function() {
Ext.MessageBox.alert('Click', 'You clicked on \"Action 1\".');
})).iconCls('blist').toDictionary());
var panel = new Ext.Panel(new Ext.PanelConfig().title('Actions').width(600).height(300).custom('bodyStyle', 'padding: 10px;').tbar([ action, { text: 'Action Menu', menu: [ action ] } ]).items([ new Ext.Button(action) ]).renderTo(ExtClass.getBody()).toDictionary());
panel.getTopToolbar().add('->', { text: 'Disable', handler: Delegate.create(this, function() {
action.setDisabled(!action.isDisabled());
this.setText(((action.isDisabled()) ? 'Enable' : 'Disable'));
}) }, { text: 'Change Text', handler: Delegate.create(this, function() {
Ext.MessageBox.prompt('Enter Text', 'Enter new text for Action 1:', Delegate.create(this, function(btn, text) {
if (btn === 'ok' && !String.isNullOrEmpty(text)) {
action.setText(text);
action.setHandler(Delegate.create(this, function() {
Ext.MessageBox.alert('Click', 'You clicked on \"' + text + '\"');
}));
}
}));
}) }, { text: 'Change Icon', handler: Delegate.create(this, function() {
action.setIconClass(((action.getIconClass()) === 'blist') ? 'bmenu' : 'blist');
}) });
}
}
Type.createNamespace('SampleScripts.grid');
////////////////////////////////////////////////////////////////////////////////
// SampleScripts.grid.ArrayGridScript
SampleScripts.grid.ArrayGridScript = function SampleScripts_grid_ArrayGridScript() {
}
SampleScripts.grid.ArrayGridScript.main = function SampleScripts_grid_ArrayGridScript$main(args) {
ExtClass.onReady(Delegate.create(null, function() {
new SampleScripts.grid.ArrayGridScript().init();
}));
}
SampleScripts.grid.ArrayGridScript.prototype = {
init: function SampleScripts_grid_ArrayGridScript$init() {
var myData = this._getMyData();
var ds = new Ext.data.Store(new Ext.data.StoreConfig().reader(new Ext.data.ArrayReader({}, [ { name: 'company' }, { name: 'price', type: 'float' }, { name: 'change', type: 'float' }, { name: 'pctChange', type: 'float' }, { name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia' } ])).toDictionary());
ds.loadData(myData);
var colModel = new Ext.grid.ColumnModel([ { id: 'company', header: 'Company', width: 160, sortable: true, locked: false, dataIndex: 'company' }, { header: 'Price', width: 75, sortable: true, renderer: Delegate.create(null, Ext.util.Format.usMoney), dataIndex: 'price' }, { header: 'Change', width: 75, sortable: true, renderer: Delegate.create(this, this._change), dataIndex: 'change' }, { header: '% Change', width: 75, sortable: true, renderer: Delegate.create(this, this._pctChange), dataIndex: 'pctChange' }, { header: 'Last Updated', width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange' } ]);
var grid = new Ext.grid.GridPanel(new Ext.grid.GridPanelConfig().el('grid-example').ds(ds).cm(colModel).autoExpandColumn('company').height(350).width(600).title('Array Grid').toDictionary());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -