2013-07-28 23:13:14 +00:00
|
|
|
'use strict';
|
|
|
|
define(
|
|
|
|
[
|
|
|
|
'app',
|
|
|
|
'marionette',
|
|
|
|
'backgrid',
|
|
|
|
'Logs/Files/FilenameCell',
|
|
|
|
'Cells/RelativeDateCell',
|
|
|
|
'Logs/Files/Collection',
|
|
|
|
'Logs/Files/Row',
|
|
|
|
'Logs/Files/ContentsView',
|
2013-08-08 03:18:26 +00:00
|
|
|
'Logs/Files/ContentsModel',
|
|
|
|
'Shared/Toolbar/ToolbarLayout'
|
|
|
|
], function (App, Marionette, Backgrid, FilenameCell, RelativeDateCell, LogFileCollection, LogFileRow, ContentsView, ContentsModel, ToolbarLayout) {
|
2013-07-28 23:13:14 +00:00
|
|
|
return Marionette.Layout.extend({
|
|
|
|
template: 'Logs/Files/LayoutTemplate',
|
|
|
|
|
|
|
|
regions: {
|
2013-08-08 03:18:26 +00:00
|
|
|
toolbar : '#x-toolbar',
|
2013-07-28 23:13:14 +00:00
|
|
|
grid : '#x-grid',
|
|
|
|
contents : '#x-contents'
|
|
|
|
},
|
|
|
|
|
|
|
|
columns:
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name : 'filename',
|
|
|
|
label: 'Filename',
|
|
|
|
cell : FilenameCell
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name : 'lastWriteTime',
|
|
|
|
label: 'Last Write Time',
|
|
|
|
cell : RelativeDateCell
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
this.collection = new LogFileCollection();
|
2013-08-08 03:18:26 +00:00
|
|
|
|
2013-07-28 23:13:14 +00:00
|
|
|
|
|
|
|
App.vent.on(App.Commands.ShowLogFile, this._showLogFile, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
onShow: function () {
|
2013-08-08 03:18:26 +00:00
|
|
|
this._fetchAndShow();
|
|
|
|
this._showToolbar();
|
2013-07-28 23:13:14 +00:00
|
|
|
this._showTable();
|
2013-08-08 03:18:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_fetchAndShow: function () {
|
|
|
|
var self = this;
|
2013-07-28 23:13:14 +00:00
|
|
|
|
2013-08-08 03:18:26 +00:00
|
|
|
var promise = this.collection.fetch();
|
|
|
|
promise.done(function () {
|
|
|
|
self._showLogFile({ model: self.collection.first() });
|
2013-07-28 23:13:14 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-08-08 03:18:26 +00:00
|
|
|
_showToolbar: function () {
|
|
|
|
|
|
|
|
var leftSideButtons = {
|
|
|
|
type : 'default',
|
|
|
|
storeState: false,
|
|
|
|
items :
|
|
|
|
[
|
|
|
|
{
|
|
|
|
title : 'Refresh',
|
|
|
|
icon : 'icon-refresh',
|
|
|
|
ownerContext : this,
|
|
|
|
callback : this._refreshLogs
|
|
|
|
},
|
2013-07-28 23:13:14 +00:00
|
|
|
|
2013-08-08 03:18:26 +00:00
|
|
|
{
|
|
|
|
title : 'Delete Log Files',
|
|
|
|
icon : 'icon-trash',
|
|
|
|
command : 'deleteLogFiles',
|
|
|
|
successMessage : 'Log files have been deleted',
|
|
|
|
errorMessage : 'Failed to delete log files',
|
|
|
|
ownerContext : this,
|
|
|
|
successCallback: this._refreshLogs
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.toolbar.show(new ToolbarLayout({
|
|
|
|
left :
|
|
|
|
[
|
|
|
|
leftSideButtons
|
|
|
|
],
|
|
|
|
context: this
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
_showTable: function () {
|
2013-07-28 23:13:14 +00:00
|
|
|
this.grid.show(new Backgrid.Grid({
|
|
|
|
row : LogFileRow,
|
|
|
|
columns : this.columns,
|
|
|
|
collection: this.collection,
|
|
|
|
className : 'table table-hover'
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
_showLogFile: function (options) {
|
2013-08-08 03:18:26 +00:00
|
|
|
|
|
|
|
this.contents.close();
|
|
|
|
|
|
|
|
if (!options.model) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-28 23:13:14 +00:00
|
|
|
var self = this;
|
|
|
|
var filename = options.model.get('filename');
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: '/log/' + filename,
|
|
|
|
success: function (data) {
|
|
|
|
var model = new ContentsModel({
|
|
|
|
filename: filename,
|
|
|
|
contents: data
|
|
|
|
});
|
|
|
|
|
|
|
|
self.contents.show(new ContentsView({ model: model }));
|
|
|
|
}
|
|
|
|
});
|
2013-08-08 03:18:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_refreshLogs: function () {
|
|
|
|
this._fetchAndShow();
|
2013-07-28 23:13:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|