partkeepr

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

AttachmentGrid.js (5080B)


      1 Ext.define('PartKeepr.AttachmentGrid', {
      2     extend: 'PartKeepr.BaseGrid',
      3     alias: 'widget.AttachmentGrid',
      4     border: false,
      5     model: null,
      6     selModel: {
      7         selType: 'rowmodel',
      8         mode: 'MULTI'
      9     },
     10     initComponent: function ()
     11     {
     12         this.store = Ext.create("Ext.data.Store", {
     13             model: this.model,
     14             proxy: {
     15                 type: 'memory',
     16                 reader: {
     17                     type: 'json'
     18                 }
     19             }
     20 
     21         });
     22 
     23         this.editing = Ext.create('Ext.grid.plugin.CellEditing', {
     24             clicksToEdit: 1
     25         });
     26 
     27         this.plugins = [this.editing];
     28 
     29         this.deleteButton = Ext.create("Ext.button.Button", {
     30             text: i18n('Delete'),
     31             disabled: true,
     32             itemId: 'delete',
     33             scope: this,
     34             iconCls: 'web-icon delete',
     35             handler: this.onDeleteClick
     36         });
     37 
     38         this.viewButton = Ext.create("Ext.button.Button", {
     39             text: i18n("View"),
     40             handler: this.onViewClick,
     41             scope: this,
     42             iconCls: 'web-icon zoom',
     43             disabled: true
     44         });
     45 
     46         this.webcamButton = Ext.create("Ext.button.Button", {
     47             text: i18n("Take image"),
     48             handler: this.onWebcamClick,
     49             scope: this,
     50             iconCls: 'fugue-icon webcam'
     51         });
     52 
     53         this.dockedItems = [
     54             {
     55                 xtype: 'toolbar',
     56                 items: [
     57                     {
     58                         text: i18n('Add'),
     59                         scope: this,
     60                         iconCls: 'web-icon attach',
     61                         handler: this.onAddClick
     62                     },
     63                     this.webcamButton,
     64                     this.viewButton,
     65                     this.deleteButton
     66                 ]
     67             }
     68         ];
     69 
     70         this.columns = [
     71             {
     72                 dataIndex: 'extension',
     73                 width: 30,
     74                 renderer: function (value, metadata, record)
     75                 {
     76                     return '<img src="' + record.getId() + '/getMimeTypeIcon"/>';
     77                 }
     78             },
     79             {
     80                 header: i18n("Filename"),
     81                 dataIndex: 'originalFilename',
     82                 width: 200
     83             },
     84             {
     85                 header: i18n("Size"),
     86                 dataIndex: 'size',
     87                 width: 80,
     88                 renderer: PartKeepr.bytesToSize
     89             },
     90             {
     91                 header: i18n("Description"),
     92                 dataIndex: 'description',
     93                 flex: 0.4,
     94                 editor: {
     95                     xtype: 'textfield',
     96                     allowBlank: true
     97                 }
     98             }
     99         ];
    100 
    101         this.callParent();
    102 
    103         this.getSelectionModel().on('selectionchange', this.onSelectChange, this);
    104         this.on("itemdblclick", this.onDoubleClick, this);
    105     },
    106     onWebcamClick: function ()
    107     {
    108         if (Ext.isIE) {
    109             Ext.MessageBox.alert(i18n("Webcam not supported"),
    110                 i18n("Internet Explorer does not support HTML5 webcams"));
    111             return;
    112         }
    113 
    114         var wp = Ext.create("PartKeepr.WebcamPanel");
    115         wp.on("fileUploaded", this.onFileUploaded, this);
    116 
    117         var j = Ext.create("Ext.window.Window", {
    118             title: i18n("Take Webcam Photo"),
    119             layout: 'fit',
    120             items: [
    121                 wp
    122             ]
    123         });
    124 
    125         wp.on("fileUploaded", function ()
    126         {
    127             j.close();
    128         });
    129 
    130         j.show();
    131     },
    132     onDoubleClick: function (view, record)
    133     {
    134         if (record) {
    135             this.viewAttachment(record);
    136         }
    137     },
    138     onAddClick: function ()
    139     {
    140         var j = Ext.create("PartKeepr.FileUploadDialog");
    141         j.on("fileUploaded", this.onFileUploaded, this);
    142         j.show();
    143     },
    144     onFileUploaded: function (response)
    145     {
    146         this.editing.cancelEdit();
    147 
    148         this.store.add(response);
    149 
    150     },
    151     onDeleteClick: function ()
    152     {
    153         this.store.remove(this.getView().getSelectionModel().getSelection());
    154     },
    155     onSelectChange: function (selModel, selections)
    156     {
    157         this.deleteButton.setDisabled(selections.length === 0);
    158         this.viewButton.setDisabled(selections.length === 0);
    159     },
    160     onViewClick: function ()
    161     {
    162         var selection = this.getView().getSelectionModel().getSelection()[0];
    163         if (selection) {
    164             this.viewAttachment(selection);
    165         }
    166     },
    167     viewAttachment: function (record)
    168     {
    169         var mySrc = record.getId() + "/getFile";
    170 
    171         new Ext.Window({
    172             title: i18n("Display File"),
    173             width: 640,
    174             height: 600,
    175             maximizable: true,
    176             constrain: true,
    177             layout: 'fit',
    178             items: [
    179                 {
    180                     xtype: "component",
    181                     autoEl: {
    182                         tag: "iframe",
    183                         src: mySrc
    184                     }
    185                 }
    186             ]
    187         }).show();
    188     }
    189 });