partkeepr

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

CategoryEditorWindow.js (1680B)


      1 Ext.define('PartKeepr.CategoryEditorWindow', {
      2     extend: 'Ext.window.Window',
      3     border: false,
      4     width: 650,
      5     categoryModel: null,
      6     layout: 'fit',
      7     items: [
      8         {
      9             xtype: "CategoryEditorForm"
     10         }
     11     ],
     12     initComponent: function () {
     13         this.buttons = [
     14             {
     15                 text: i18n("Save"),
     16                 handler: Ext.bind(this.onSave, this)
     17             }, {
     18                 text: i18n("Cancel"),
     19                 handler: Ext.bind(this.onCancel, this)
     20             }
     21         ];
     22 
     23         this.callParent();
     24 
     25         if (!this.record.phantom)
     26         {
     27             this.setTitle(i18n("Edit Category"));
     28         } else
     29         {
     30             this.record.set("parent", this.parentRecord.getId());
     31             this.setTitle(i18n("Add Category"));
     32         }
     33 
     34         this.down("CategoryEditorForm").loadRecord(this.record);
     35 
     36         this.down("textfield[name=name]").on("keypress", this.onEnter, this);
     37         this.down("htmleditor[name=description]").on("keypress", this.onEnter, this);
     38 
     39         this.on("show", Ext.bind(this._onShow, this));
     40     },
     41     onEnter: function (field, e) {
     42         if (e.getKey() == e.ENTER)
     43         {
     44             this.onSave();
     45         }
     46     },
     47     _onShow: function () {
     48         this.down("CategoryEditorForm").items.first().focus();
     49     },
     50     onSave: function () {
     51         this.down("CategoryEditorForm").updateRecord(this.record);
     52 
     53         this.record.save({
     54             success: Ext.bind(function (response) {
     55                 this.fireEvent("save", response);
     56                 this.destroy();
     57             }, this)
     58         });
     59     },
     60     onCancel: function () {
     61         this.destroy();
     62     }
     63 });