Scribe.js/static/js/controllers/folderController.js

62 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-11-11 21:20:33 +01:00
(function () {
'use strict';
2014-11-13 21:33:37 +01:00
/**
* Folder controller
*/
2014-11-11 21:20:33 +01:00
window.app.controller('folderController', [
'$scope',
'$rootScope',
'logs',
'folder',
function ($scope, $rootScope, logs, folder) {
2014-11-13 21:33:37 +01:00
//reset
2014-11-11 21:20:33 +01:00
$rootScope.sidebar = false;
$scope.onlyFiles = true;
2014-11-13 21:33:37 +01:00
//build each block
2014-11-11 21:20:33 +01:00
$scope.blocks = folder.map(function (item) {
if (item.type !== 'file') {
$scope.onlyFiles = false;
}
return {
message : item.name,
click : function () {
if (item.type === 'file') {
2014-11-13 21:33:37 +01:00
//Save all current files of the folder
2014-11-11 21:20:33 +01:00
//But select only the clicked one
var newFiles = folder.map(function (file) {
if (file.type === 'file') {
return {
selected : file.path === item.path,
name : file.name,
path : file.path
};
} else {
return null;
}
});
2014-11-13 21:33:37 +01:00
//save files and redirect
2014-11-11 21:20:33 +01:00
logs.setLogs(newFiles);
$rootScope.go('logs');
} else {
$rootScope.go('folder', {
path : item.path
});
}
}
};
});
}
]);
}());