Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ext.onReady(function(){
- Ext.QuickTips.init();
- var simple = new Ext.FormPanel({
- labelWidth: 75, // label settings here cascade unless overridden
- url:'save-form.php',
- labelAlign: 'top',
- frame:false,
- title: 'Basic',
- bodyStyle:'padding:5px 5px 0',
- width: 800,
- defaultType: 'textfield',
- layout: 'tableform',
- layoutConfig: {
- tableAttrs: {
- style: { width: '100%' }
- },
- columnWidths: [0.5,0.5],
- columns: 2,
- extraCls: 'simple-account-form-table'
- },
- defaults: {bodyStyle: 'padding:10px', width: 225},
- items: [
- {
- fieldLabel: 'Account Name',
- name: 'first',
- xtype: 'textfield',
- allowBlank:false,
- maxLength: 100,
- value: '<%=@account.last_name%>'
- },{
- fieldLabel: 'Uppercase Account Name',
- xtype: 'textfield',
- name: 'first',
- allowBlank:false,
- value: '<%=@account.upper_last_name%>'
- },{
- fieldLabel: 'Account Type',
- xtype: 'textfield',
- name: 'last',
- grow: true,
- width: 300,
- value: '<%=@account.account_type%>'
- }, {
- fieldLabel: 'Division',
- xtype: 'textfield',
- name: 'company',
- grow: true,
- value: '<%=@account.division.description%>'
- }, new Ext.form.NumberField({
- fieldLabel: 'Bill Day',
- name: 'time',
- allowBlank: false,
- decimalPrecision: 0,
- maxLength: 28,
- minLength: 1,
- value: '<%=@account.bill_day%>',
- grow: true
- }), new Ext.form.Checkbox ({
- fieldLabel: 'Billable?',
- checked: <%=@account.billable?%>
- }), {
- fieldLabel: 'Sell Currency',
- xtype: 'textfield',
- name: 'first',
- allowBlank:false,
- value: '<%=@account.sell_currency_id%>',
- grow: true
- }, {
- fieldLabel: 'Buy Currency',
- xtype: 'textfield',
- name: 'last',
- value: '<%=@account.buy_currency_id%>',
- grow: true
- }, /* TODO: need to find out more about this field{
- fieldLabel: 'Class',
- name: 'company',
- xtype: 'textfield',
- value: '<%=@account.attributes['class']%>'
- }*/
- ]/*,
- buttons: [{
- text: 'Save'
- },{
- text: 'Cancel'
- }] */
- });
- var contactTypeStore = new Ext.data.ArrayStore({
- id: 'contact-type-store',
- data: <%= ContactType.collection_for_select.to_json %>,
- fields: ['label', 'id']
- });
- var countryStore = new Ext.data.ArrayStore({
- data: <%= Country.collection_for_select.to_json %>,
- fields: ['label', 'id']
- });
- var countryCombo = new Ext.form.ComboBox({
- store: countryStore,
- typeAhead: false,
- mode: 'local',
- triggerAction: 'all',
- editable: false,
- width: 75,
- displayField: 'label',
- valueField: 'id'
- });
- var contactTypeCombo = new Ext.form.ComboBox({
- store: contactTypeStore,
- typeAhead: false,
- mode: 'local',
- triggerAction: 'all',
- editable: false,
- width: 75,
- displayField: 'label',
- valueField: 'id'
- });
- var contactReader = new Ext.data.JsonReader({
- idProperty: 'id',
- root: 'data',
- fields: [
- {name: 'id'},
- {name: 'contact_type_id',
- sortType: function(value) {
- var index = contactTypeStore.find("id", value);
- var result = contactTypeStore.getAt(index)
- return result.get('label');
- }},
- {name: 'active?', type: 'bool'},
- {name: 'contact_id'},
- {name: 'contact.first_name', allowBlank: true},
- {name: 'contact.last_name', allowBlank: true},
- {name: 'contact.title', allowBlank: true},
- {name: 'contact.email', allowBlank: true},
- {name: 'contact.office', allowBlank: true},
- {name: 'contact.cell', allowBlank: true},
- {name: 'contact.fax', allowBlank: true},
- {name: 'contact.pager', allowBlank: true},
- {name: 'contact.internal'},
- {name: 'contact.notes', allowBlank: true},
- {name: 'address.street', mapping: 'contact.address', convert: function(v){
- return v ? v.street : undefined;
- }},
- {name: 'address.city', mapping: 'contact.address', convert: function(v){
- return v ? v.city :undefined;
- }},
- {name: 'address.state', mapping: 'contact.address', convert: function(v){
- return v ? v.state : undefined;
- }},
- {name: 'address.zip_code', mapping: 'contact.address', convert: function(v){
- return v ? v.zip_code : undefined;
- }},
- {
- name: 'address.country_id',
- mapping: 'contact.address',
- convert: function(v){
- return v ? v.country_id : undefined;
- },
- sortType: function(value) {
- var index = countryStore.find("id", value);
- var result = countryStore.getAt(index)
- return result.get('label');
- }
- }
- ,
- {name: 'address.street2', mapping: 'contact.address', convert: function(v){
- return v ? v.street2 : undefined;
- }}
- ]
- });
- var contactsStore = new Ext.data.GroupingStore({
- id: 'contactsJsonStore',
- sortInfo: {
- field: 'contact_type_id',
- direction: 'ASC' // or 'DESC' (case sensitive for local sorting)
- },
- reader: contactReader,
- proxy: new Ext.data.HttpProxy({
- url: '<%=account_contacts_path(@account)%>',
- method: 'GET'
- }),
- groupField: 'contact.internal',
- listeners: {
- beforeload: function(store){
- if (contactsGrid && contactsGrid.el) {
- contactsGrid.el.mask('Please wait while we refresh the data', 'x-mask-loading');
- }
- },
- load: function(store){
- if (contactsGrid && contactsGrid.el){
- contactsGrid.el.unmask();
- }
- }
- }
- });
- contactsStore.load();
- var editor = new Ext.ux.grid.RowEditor({
- saveText: 'Update'
- });
- var contactsGrid = new Ext.grid.GridPanel({
- store: contactsStore,
- title: "Active Accounts",
- height: 400,
- margins: '0 5 5 5',
- readOnly: false,
- //plugins: [editor],
- listeners: {
- activate: function(panel){
- console.log("activate!!!");
- }
- },
- frame:false,
- tbar: [ new Ext.form.Checkbox({
- boxLabel: 'Show Inactive',
- listeners: {
- check: function(checkbox, checked){
- if (checked){
- contactsStore.reload({
- params: {
- show_inactive: true
- }
- });
- contactsGrid.setTitle("All Accounts");
- } else {
- contactsStore.reload({
- params: {
- show_inactive: false
- }
- });
- contactsGrid.setTitle("Active Accounts");
- }
- }
- }
- })
- ],
- view: new Ext.grid.GroupingView({
- groupTextTpl: '<tpl if="groupId.indexOf(\'internal\') != -1 && gvalue==\'Y\'">Internal Contacts</tpl>' +
- '<tpl if="groupId.indexOf(\'internal\') != -1 && gvalue==\'N\'">External Contacts</tpl>' +
- '<tpl if="groupId.indexOf(\'internal\') == -1">{text}</tpl>'
- }),
- columns: [
- {
- header: "Type",
- width: 150,
- dataIndex: 'contact_type_id',
- sortable: true,
- triggerAction: 'all',
- editor: contactTypeCombo,
- renderer: Ext.util.Format.comboRenderer(contactTypeCombo)
- },
- {
- id: 'contact_first_name',
- header: 'FirstName',
- dataIndex: 'contact.first_name',
- width: 150,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- }, {
- id: 'contact_first_name',
- header: 'Last Name',
- dataIndex: 'contact.last_name',
- width: 150,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- }, new Ext.grid.CheckColumn({
- header: 'Active?',
- dataIndex: 'active?',
- width: 55,
- disabled: true
- }), {
- id: 'contact_title',
- header: 'Title',
- dataIndex: 'contact.title',
- width: 100,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- }, {
- id: 'contact_email',
- header: 'Email',
- dataIndex: 'contact.email',
- width: 150,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- }, {
- id: 'contact_office',
- header: 'Office',
- dataIndex: 'contact.office',
- width: 100,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- }, {
- id: 'contact_cell',
- header: 'Cell',
- dataIndex: 'contact.cell',
- width: 100,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- }, {
- id: 'contact_fax',
- header: 'Fax',
- dataIndex: 'contact.fax',
- width: 100,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- }, {
- id: 'contact_pager',
- header: 'Pager',
- dataIndex: 'contact.pager',
- width: 100,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- }, {
- id: 'contact_internal',
- header: 'Internal',
- dataIndex: 'contact.internal',
- width: 50,
- sortable: true,
- align: 'center',
- editor: {
- xtype: 'textfield',
- allowBlank: false
- }
- }, {
- id: 'contact_name',
- header: 'Notes',
- dataIndex: 'contact.notes',
- width: 200,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- }, {
- id: 'address_id',
- header: 'Street',
- dataIndex: 'address.street',
- width: 100,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- }, {
- id: 'address_id',
- header: 'Street Line 2',
- dataIndex: 'address.street2',
- width: 100,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- },
- {
- id: 'address_id',
- header: 'City',
- dataIndex: 'address.city',
- width: 75,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- },
- {
- id: 'address_id',
- header: 'State',
- dataIndex: 'address.state',
- width: 75,
- sortable: true,
- editor: {
- xtype: 'textfield',
- allowBlank: true
- }
- },
- {
- id: 'address_id',
- header: 'Country',
- dataIndex: 'address.country_id',
- width: 75,
- sortable: true,
- editor: countryCombo,
- renderer: Ext.util.Format.comboRenderer(countryCombo)
- }
- ],
- sm: new Ext.grid.RowSelectionModel({singleSelect:true})
- });
- var accountPanel = new Ext.Panel({
- renderTo: 'account-form',
- labelAlign: 'top',
- title: 'Account Information',
- bodyStyle:'padding:5px',
- width: 900,
- items: [{
- xtype:'tabpanel',
- activeTab: 0,
- defaults:{autoHeight:true, bodyStyle:'padding:10px'},
- frame:false,
- items:[simple ,{
- title:'Contacts',
- items: [contactsGrid],
- listeners: {
- click: function(panel){
- console.log("click");
- }
- }
- }, {
- title:'Other',
- layout:'form',
- defaults: {width: 230},
- defaultType: 'displayfield',
- items: [
- <% if @account.active_date %>{
- fieldLabel: "Active Date",
- value: '<%=@account.active_date%>'
- },
- <% end %>
- <% if @account.inactive_date%> {
- fieldLabel: "Inactive Date",
- value: '<%=@account.inactive_date%>'
- },
- <% end %>
- {
- fieldLabel: 'Entered Date',
- value: '<%= @account.entered_date %>'
- },{
- fieldLabel: 'Created Date',
- value: '<%= @account.create_date %>'
- },{
- fieldLabel: 'Created By',
- value: '<%= @account.create_uid %>'
- },{
- fieldLabel: 'Updated Date',
- value: '<%= @account.update_date %>'
- }, {
- fieldLabel: 'Updated By',
- value: '<%= @account.update_uid %>'
- }]
- }]
- }]
- });
- });
Add Comment
Please, Sign In to add comment