partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

ManufacturerEditor.js (4121B)


      1 Ext.define('PartKeepr.ManufacturerEditor', {
      2     extend: 'PartKeepr.Editor',
      3     alias: 'widget.ManufacturerEditor',
      4     saveText: i18n("Save Manufacturer"),
      5     labelWidth: 150,
      6     initComponent: function ()
      7     {
      8         this.on("startEdit", Ext.bind(this.onEditStart, this));
      9 
     10         this.tpl = new Ext.XTemplate(
     11             '<tpl for=".">',
     12             '<div class="dataview-multisort-item iclogo"><img src="{[values["@id"]]}/getImage?maxWidth=100&maxHeight=100"/></div>',
     13             '</tpl>');
     14 
     15         this.addLogoButton = Ext.create("Ext.button.Button", {
     16             iconCls: "web-icon add",
     17             text: i18n("Add Logo"),
     18             handler: Ext.bind(this.uploadImage, this)
     19         });
     20 
     21         this.deleteLogoButton = Ext.create("Ext.button.Button", {
     22             iconCls: "web-icon delete",
     23             text: i18n("Delete Logo"),
     24             disabled: true,
     25             handler: Ext.bind(this.deleteImage, this)
     26         });
     27 
     28         this.iclogoGrid = Ext.create("Ext.view.View", {
     29             store: null,
     30             border: true,
     31             frame: true,
     32             style: 'background-color: white',
     33             emptyText: 'No images to display',
     34             height: 200,
     35             fieldLabel: i18n("Logos"),
     36             componentCls: 'manufacturer-ic-logos',
     37             itemSelector: 'div.dataview-multisort-item',
     38             singleSelect: true,
     39             anchor: '100%',
     40             tpl: this.tpl,
     41             listeners: {
     42                 selectionchange: Ext.bind(function (view, selections)
     43                 {
     44                     if (selections.length > 0) {
     45                         this.deleteLogoButton.enable();
     46                     } else {
     47                         this.deleteLogoButton.disable();
     48                     }
     49                 }, this)
     50             }
     51         });
     52 
     53         this.items = [
     54             {
     55                 xtype: 'textfield',
     56                 name: 'name',
     57                 fieldLabel: i18n("Manufacturer Name")
     58             }, {
     59                 xtype: 'textarea',
     60                 name: 'address',
     61                 fieldLabel: i18n("Address")
     62             }, {
     63                 xtype: 'urltextfield',
     64                 name: 'url',
     65                 fieldLabel: i18n("Website")
     66             }, {
     67                 xtype: 'textfield',
     68                 name: 'email',
     69                 fieldLabel: i18n("Email")
     70             }, {
     71                 xtype: 'textfield',
     72                 name: 'phone',
     73                 fieldLabel: i18n("Phone")
     74             }, {
     75                 xtype: 'textfield',
     76                 name: 'fax',
     77                 fieldLabel: i18n("Fax")
     78             }, {
     79                 xtype: 'textarea',
     80                 name: 'comment',
     81                 fieldLabel: i18n("Comment")
     82             }, {
     83                 xtype: 'fieldcontainer',
     84                 fieldLabel: i18n("Manufacturer Logos"),
     85                 items: [
     86                     {
     87                         xtype: 'panel',
     88                         dockedItems: [
     89                             {
     90                                 xtype: 'toolbar',
     91                                 dock: 'bottom',
     92                                 items: [this.addLogoButton, this.deleteLogoButton]
     93                             }
     94                         ],
     95                         items: this.iclogoGrid
     96                     }
     97                 ]
     98 
     99             }
    100         ];
    101 
    102 
    103         this.on("itemSaved", this._onItemSaved, this);
    104         this.callParent();
    105 
    106     },
    107     _onItemSaved: function (record)
    108     {
    109         this.iclogoGrid.bindStore(record.icLogos());
    110     },
    111     onFileUploaded: function (response)
    112     {
    113         this.iclogoGrid.getStore().add(response);
    114     },
    115     uploadImage: function ()
    116     {
    117         var j = Ext.create("PartKeepr.FileUploadDialog", {imageUpload: true});
    118         j.on("fileUploaded", Ext.bind(this.onFileUploaded, this));
    119         j.show();
    120     },
    121     deleteImage: function ()
    122     {
    123         this.iclogoGrid.getStore().remove(this.iclogoGrid.getSelectionModel().getLastSelected());
    124     },
    125     onEditStart: function ()
    126     {
    127         var store = this.record.icLogos();
    128         this.iclogoGrid.bindStore(store);
    129     }
    130 });