You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.6 KiB
141 lines
4.6 KiB
11 years ago
|
'use strict';
|
||
|
define(
|
||
|
[
|
||
|
'app',
|
||
|
'marionette',
|
||
|
'backgrid',
|
||
11 years ago
|
'System/Logs/Files/FilenameCell',
|
||
11 years ago
|
'Cells/RelativeDateCell',
|
||
11 years ago
|
'System/Logs/Files/LogFileCollection',
|
||
|
'System/Logs/Files/Row',
|
||
|
'System/Logs/Files/ContentsView',
|
||
|
'System/Logs/Files/ContentsModel',
|
||
|
'Shared/Toolbar/ToolbarLayout',
|
||
|
'Shared/LoadingView'
|
||
|
], function (App, Marionette, Backgrid, FilenameCell, RelativeDateCell, LogFileCollection, LogFileRow, ContentsView, ContentsModel, ToolbarLayout, LoadingView) {
|
||
11 years ago
|
return Marionette.Layout.extend({
|
||
11 years ago
|
template: 'System/Logs/Files/LogFileLayoutTemplate',
|
||
11 years ago
|
|
||
|
regions: {
|
||
11 years ago
|
toolbar : '#x-toolbar',
|
||
11 years ago
|
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();
|
||
11 years ago
|
|
||
11 years ago
|
App.vent.on(App.Commands.ShowLogFile, this._showLogFile, this);
|
||
11 years ago
|
App.vent.on(App.Events.CommandComplete, this._commandComplete, this);
|
||
11 years ago
|
},
|
||
|
|
||
|
onShow: function () {
|
||
11 years ago
|
this._fetchAndShow();
|
||
|
this._showToolbar();
|
||
11 years ago
|
this._showTable();
|
||
11 years ago
|
},
|
||
|
|
||
|
_fetchAndShow: function () {
|
||
|
var self = this;
|
||
11 years ago
|
|
||
11 years ago
|
this.contents.close();
|
||
|
|
||
11 years ago
|
var promise = this.collection.fetch();
|
||
|
promise.done(function () {
|
||
11 years ago
|
if (self.collection.length > 0) {
|
||
|
self._showLogFile({ model: self.collection.first() });
|
||
|
}
|
||
11 years ago
|
});
|
||
|
},
|
||
|
|
||
11 years ago
|
_showToolbar: function () {
|
||
|
|
||
11 years ago
|
var rightSideButtons = {
|
||
11 years ago
|
type : 'default',
|
||
|
storeState: false,
|
||
|
items :
|
||
|
[
|
||
|
{
|
||
|
title : 'Refresh',
|
||
|
icon : 'icon-refresh',
|
||
|
ownerContext : this,
|
||
|
callback : this._refreshLogs
|
||
|
},
|
||
11 years ago
|
|
||
11 years ago
|
{
|
||
|
title : 'Delete Log Files',
|
||
|
icon : 'icon-trash',
|
||
|
command : 'deleteLogFiles',
|
||
|
successMessage : 'Log files have been deleted',
|
||
11 years ago
|
errorMessage : 'Failed to delete log files'
|
||
11 years ago
|
}
|
||
|
]
|
||
|
};
|
||
|
|
||
|
this.toolbar.show(new ToolbarLayout({
|
||
11 years ago
|
right :
|
||
11 years ago
|
[
|
||
11 years ago
|
rightSideButtons
|
||
11 years ago
|
],
|
||
|
context: this
|
||
|
}));
|
||
|
},
|
||
|
|
||
|
_showTable: function () {
|
||
11 years ago
|
this.grid.show(new Backgrid.Grid({
|
||
|
row : LogFileRow,
|
||
|
columns : this.columns,
|
||
|
collection: this.collection,
|
||
|
className : 'table table-hover'
|
||
|
}));
|
||
|
},
|
||
|
|
||
|
_showLogFile: function (options) {
|
||
11 years ago
|
this.contents.show(new LoadingView());
|
||
11 years ago
|
|
||
|
if (!options.model) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
11 years ago
|
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 }));
|
||
|
}
|
||
|
});
|
||
11 years ago
|
},
|
||
|
|
||
|
_refreshLogs: function () {
|
||
|
this._fetchAndShow();
|
||
11 years ago
|
},
|
||
|
|
||
|
_commandComplete: function (options) {
|
||
|
if (options.command.get('name') === 'deletelogfiles') {
|
||
|
this._refreshLogs();
|
||
|
}
|
||
11 years ago
|
}
|
||
|
});
|
||
|
});
|