partkeepr

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

MetaPartEditorWindow.js (3144B)


      1 /**
      2  * @class PartKeepr.Components.Part.Editor.MetaPartEditorWindow
      3 
      4  * <p>The MetaPartEditorWindow encapsulates the PartKeepr.Components.Part.Editor.MetaPartEditor within a window.</p>
      5  */
      6 Ext.define('PartKeepr.Components.Part.Editor.MetaPartEditorWindow', {
      7     extend: 'Ext.window.Window',
      8 
      9     /* Constrain the window to fit the viewport */
     10     constrainHeader: true,
     11 
     12     /* Fit the editor within the window */
     13     layout: 'fit',
     14 
     15     /* Width and height settings */
     16     width: 600,
     17     minWidth: 600,
     18     minHeight: 415,
     19     height: 415,
     20 
     21     border: false,
     22 
     23     saveText: i18n("Save"),
     24     cancelText: i18n("Cancel"),
     25 
     26     title: i18n("Add/Edit Meta-Part"),
     27 
     28     saveButtonReenableTask: null,
     29 
     30     /**
     31      * Creates the part editor and put it into the window.
     32      */
     33     initComponent: function ()
     34     {
     35         this.editor = Ext.create("PartKeepr.Components.Part.Editor.MetaPartEditor", {
     36             border: false,
     37             enableButtons: false
     38         });
     39 
     40         this.items = [this.editor];
     41 
     42         this.editor.on("editorClose", function ()
     43         {
     44             this.close();
     45         }, this, {delay: 200});
     46 
     47         this.editor.on("_titleChange", function (val)
     48         {
     49             this.setTitle(val);
     50         }, this);
     51         this.editor.on("itemSaved", this.onItemSaved, this);
     52 
     53         this.saveButton = Ext.create("Ext.button.Button", {
     54             text: this.saveText,
     55             iconCls: 'fugue-icon disk',
     56             handler: Ext.bind(this.onItemSave, this)
     57         });
     58 
     59         this.cancelButton = Ext.create("Ext.button.Button", {
     60             text: this.cancelText,
     61             iconCls: 'web-icon cancel',
     62             handler: Ext.bind(this.onCancelEdit, this)
     63         });
     64 
     65         this.bottomToolbar = Ext.create("Ext.toolbar.Toolbar", {
     66             enableOverflow: true,
     67             defaults: {minWidth: 100},
     68             dock: 'bottom',
     69             ui: 'footer',
     70             pack: 'start',
     71             items: [this.saveButton, this.cancelButton]
     72         });
     73 
     74         this.dockedItems = [this.bottomToolbar];
     75 
     76         this.callParent();
     77     },
     78     onCancelEdit: function ()
     79     {
     80         this.editor.onCancelEdit();
     81     },
     82     /**
     83      * Called when the save button was clicked
     84      */
     85     onItemSave: function ()
     86     {
     87         if (!this.editor.getForm().isValid()) {
     88             return;
     89         }
     90 
     91         // Disable the save button to indicate progress
     92         this.saveButton.disable();
     93 
     94         // Sanity: If the save process fails, re-enable the button after 30 seconds
     95         if (this.saveButtonReenableTask === null) {
     96             this.saveButtonReenableTask = new Ext.util.DelayedTask(function ()
     97             {
     98                 this.saveButton.enable();
     99             }, this);
    100             this.on('destroy', function ()
    101             {
    102                 this.saveButtonReenableTask.cancel();
    103             }, this);
    104         }
    105         this.saveButtonReenableTask.delay(30000);
    106 
    107         if (!this.editor._onItemSave()) {
    108             this.saveButton.enable();
    109         }
    110     },
    111     /**
    112      * Called when the item was saved
    113      */
    114     onItemSaved: function ()
    115     {
    116         this.saveButton.enable();
    117     }
    118 });