FR.components.commentsPanel = Ext.extend(Ext.ux.ListPanel, { path: false, title: '', initComponent: function() { this.store = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: URLRoot+'/?module=comments§ion=ajax&page=load' }), reader: new Ext.data.JsonReader({ root: 'comments', totalProperty: 'totalCount', id: 'id', fields: ['id', 'date_added', 'timer', 'uid', 'val', 'username', 'fullName', 'self', 'followup'] }) }); this.store.on('beforeload', function() { this.grid.getEl().update('
'+FR.T('Loading...')+'
'); }, this); this.store.on('exception', function() { this.grid.getEl().update('
'+FR.T('Failed to load comments data')+'
'); }, this); this.store.on('load', function(store) { var d = store.reader.jsonData; if (d.msg) { if (d.totalCount > 0) { FR.UI.feedback(d.msg); } else { this.grid.getEl().update('
'+d.msg+'
'); } } FR.utils.applyFileUpdates(d.path, {comments: d.totalCount}); this.grid.el.scroll('b', 10000, true); }, this); this.btns = { print: new Ext.Button({ cls: 'fr-btn-smaller fr-btn-print-comments', iconCls: 'fa fa-fw fa-print', handler: this.print, scope: this }) }; var tpl = '
'+ '
' + ''+ '
own followup">'+ '
{fullName}
' + '
{timer}
' + '
{fullName}
' + '
'+ '
' + '
'; if (User.perms.write_comments){ tpl += '
'; } tpl += '{val}'+ '
'+ '
'+ '
'+ '
'+ '
'+ '
'; tpl = new Ext.XTemplate(tpl); this.grid = new Ext.DataView({ region: 'center', autoScroll: true, flex:1, tpl: tpl, store: this.store, emptyText: '' }); this.inputBox = new Ext.form.TextArea({ flex: 1, emptyText: FR.T('Write a comment...'), enableKeyEvents: true, listeners: { 'render': function() { this.inputBox.el.set({'placeholder': FR.T('Write a comment...')}); }, 'keydown': function(field, e) { if (e.getKey() == e.ENTER) {if (!e.shiftKey) {this.addComment();}} }, scope: this } }); this.writePanel = new Ext.Panel({ region: 'south', layout: 'fit', cls: 'commentField', height: 84, layoutConfig: { align: "stretch" }, items: this.inputBox, tbar: {style: 'padding:1px 2px;', items: ['->' , this.btns.print]} }); Ext.apply(this, { layout: 'border', items: [ this.grid, this.writePanel ], listeners: { 'activate': function(p) { p.active = true; if (this.isSet()) { this.inputBox.focus(); this.load(); } }, 'deactivate': function(p) {p.active = false;} } }); FR.components.commentsPanel.superclass.initComponent.apply(this, arguments); }, isSet: function() { return this.path; }, setItem: function(item) { var path = item.data.path; var cCount = item.data.comments; if (path == this.path) {return this;} this.store.removeAll(true); if (this.active) { this.grid.refresh(); } if (FR.utils.canAddComments()) { this.writePanel.show(); } else { this.writePanel.hide(); } this.doLayout(true); this.setTitleNumber(cCount); this.path = path; this.store.setBaseParam('path', path); if (!this.collapsed) { this.load(); } return this; }, load: function() { if (!this.active) {return false;} this.store.load(); }, addComment: function() { var c = encodeURIComponent(this.inputBox.getValue()); if (c.length > 0) { this.action('add', {comment: c}); } }, print: function() { window.open(URLRoot+'/?module=comments&page=print&path='+encodeURIComponent(this.path)); }, deleteComment: function(cid) { new Ext.ux.prompt({ text: FR.T('Are you sure you want to remove the comment?'), confirmHandler: function() { this.action('remove', {commentId: encodeURIComponent(cid)}); }, scope: this }); }, showLoading: function () {this.getEl().mask(FR.T('Loading...'));}, hideLoading: function () {this.getEl().unmask();}, action: function(action, params, callback) { this.showLoading(); Ext.Ajax.request({ url: URLRoot+'/?module=comments§ion=ajax&page='+action, params: Ext.apply(this.store.baseParams, params), success: function(req) { this.hideLoading(); try { var rs = Ext.decode(req.responseText); } catch (er){return false;} if (rs) { if (rs.success) { if (callback) {callback.call();} this.inputBox.reset(); this.load(); } if (rs.msg) { FR.UI.feedback(rs.msg); } } }, scope: this }); } }); FR.UI.deleteComment = function(panelId, cId) {Ext.getCmp(panelId).deleteComment(cId);};