File modal refactoring + orphan files selection

This commit is contained in:
jendib 2015-03-28 00:09:28 +01:00
parent 80a2e0d055
commit 0d4643cc93
8 changed files with 34 additions and 21 deletions

View File

@ -134,7 +134,7 @@ angular.module('docs',
} }
}) })
.state('document.add', { .state('document.add', {
url: '/add', url: '/add?files',
views: { views: {
'document': { 'document': {
templateUrl: 'partial/docs/document.edit.html', templateUrl: 'partial/docs/document.edit.html',
@ -143,7 +143,7 @@ angular.module('docs',
} }
}) })
.state('document.edit', { .state('document.edit', {
url: '/edit/:id', url: '/edit/:id?files',
views: { views: {
'document': { 'document': {
templateUrl: 'partial/docs/document.edit.html', templateUrl: 'partial/docs/document.edit.html',

View File

@ -71,9 +71,12 @@ angular.module('docs').controller('DocumentDefault', function($scope, $state, Re
/** /**
* Delete a file. * Delete a file.
*/ */
$scope.deleteFile = function (file) { $scope.deleteFile = function ($event, file) {
$event.stopPropagation();
Restangular.one('file', file.id).remove().then(function () { Restangular.one('file', file.id).remove().then(function () {
$scope.loadFiles(); $scope.loadFiles();
}); });
return false;
}; };
}); });

View File

@ -4,8 +4,6 @@
* File modal view controller. * File modal view controller.
*/ */
angular.module('docs').controller('FileModalView', function($rootScope, $modalInstance, $scope, $state, $stateParams, Restangular) { angular.module('docs').controller('FileModalView', function($rootScope, $modalInstance, $scope, $state, $stateParams, Restangular) {
var view = $stateParams.id ? 'document.view.file' : 'document.default.file';
// Load files // Load files
Restangular.one('file').getList('list', { id: $stateParams.id }).then(function(data) { Restangular.one('file').getList('list', { id: $stateParams.id }).then(function(data) {
$scope.files = data.files; $scope.files = data.files;
@ -26,7 +24,7 @@ angular.module('docs').controller('FileModalView', function($rootScope, $modalIn
if (value.id == $stateParams.fileId) { if (value.id == $stateParams.fileId) {
var next = $scope.files[key + 1]; var next = $scope.files[key + 1];
if (next) { if (next) {
$state.transitionTo(view, { id: $stateParams.id, fileId: next.id }); $state.go('^.file', { id: $stateParams.id, fileId: next.id });
} }
} }
}); });
@ -40,7 +38,7 @@ angular.module('docs').controller('FileModalView', function($rootScope, $modalIn
if (value.id == $stateParams.fileId) { if (value.id == $stateParams.fileId) {
var previous = $scope.files[key - 1]; var previous = $scope.files[key - 1];
if (previous) { if (previous) {
$state.transitionTo(view, { id: $stateParams.id, fileId: previous.id }); $state.go('^.file', { id: $stateParams.id, fileId: previous.id });
} }
} }
}); });
@ -74,7 +72,7 @@ angular.module('docs').controller('FileModalView', function($rootScope, $modalIn
// Close the modal when the user exits this state // Close the modal when the user exits this state
var off = $rootScope.$on('$stateChangeStart', function(event, toState) { var off = $rootScope.$on('$stateChangeStart', function(event, toState) {
if (!$modalInstance.closed) { if (!$modalInstance.closed) {
if (toState.name == view) { if (toState.name == $state.current.name) {
$modalInstance.close(); $modalInstance.close();
} else { } else {
$modalInstance.dismiss(); $modalInstance.dismiss();

View File

@ -16,10 +16,6 @@ angular.module('docs').controller('FileView', function($modal, $state, $statePar
modal.closed = true; modal.closed = true;
}, function() { }, function() {
modal.closed = true; modal.closed = true;
if ($stateParams.id) { $state.go('^', { id: $stateParams.id });
$state.transitionTo('document.view', { id: $stateParams.id });
} else {
$state.transitionTo('document.default');
}
}); });
}); });

View File

@ -3,7 +3,7 @@
/** /**
* Tag controller. * Tag controller.
*/ */
angular.module('docs').controller('Tag', function($scope, $dialog, $state, Tag, Restangular) { angular.module('docs').controller('Tag', function($scope, $dialog, Tag, Restangular) {
$scope.tag = { name: '', color: '#3a87ad' }; $scope.tag = { name: '', color: '#3a87ad' };
// Retrieve tags // Retrieve tags
@ -14,7 +14,7 @@ angular.module('docs').controller('Tag', function($scope, $dialog, $state, Tag,
// Retrieve tag stats // Retrieve tag stats
Restangular.one('tag/stats').get().then(function(data) { Restangular.one('tag/stats').get().then(function(data) {
$scope.stats = data.stats; $scope.stats = data.stats;
}) });
/** /**
* Returns total number of document from tag stats. * Returns total number of document from tag stats.

View File

@ -5,16 +5,19 @@
{{ app.document_count }} <small>document{{ app.document_count > 1 ? 's' : '' }} in the database</small> {{ app.document_count }} <small>document{{ app.document_count > 1 ? 's' : '' }} in the database</small>
</h1> </h1>
<div class="row" ng-model="dropFiles" style="min-height: 150px;" ng-file-drop drag-over-class="bg-success" <div class="row upload-zone" ng-model="dropFiles" ng-file-drop drag-over-class="bg-success"
ng-multiple="true" allow-dir="false" accept="image/*,application/pdf,application/zip" ng-file-change="fileDropped($files, $event, $rejectedFiles)"> ng-multiple="true" allow-dir="false" accept="image/*,application/pdf,application/zip" ng-file-change="fileDropped($files, $event, $rejectedFiles)">
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-center" ng-repeat="file in files"> <div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-center" ng-repeat="file in files">
<div class="thumbnail" ng-if="file.id"> <div class="thumbnail" ng-class="{ 'thumbnail-checked': file.checked }" ng-if="file.id">
<a ng-click="openFile(file)"> <a ng-click="openFile(file)">
<img class="thumbnail-file" ng-src="../api/file/{{ file.id }}/data?size=thumb" tooltip="{{ file.mimetype }}" tooltip-placement="top" /> <img class="thumbnail-file" ng-src="../api/file/{{ file.id }}/data?size=thumb" tooltip="{{ file.mimetype }}" tooltip-placement="top" />
</a> </a>
<div class="caption"> <div class="caption pointer" ng-click="file.checked = !file.checked">
<div class="pull-left">
<input type="checkbox" ng-model="file.checked" />
</div>
<div class="pull-right"> <div class="pull-right">
<button class="btn btn-danger" ng-click="deleteFile(file)"><span class="glyphicon glyphicon-trash"></span></button> <button class="btn btn-danger" ng-click="deleteFile($event, file)"><span class="glyphicon glyphicon-trash"></span></button>
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>

View File

@ -35,7 +35,7 @@
<div ng-file-drop drag-over-class="bg-success" ng-multiple="true" allow-dir="false" ng-model="dropFiles" <div ng-file-drop drag-over-class="bg-success" ng-multiple="true" allow-dir="false" ng-model="dropFiles"
accept="image/*,application/pdf,application/zip" ng-file-change="fileDropped($files, $event, $rejectedFiles)"> accept="image/*,application/pdf,application/zip" ng-file-change="fileDropped($files, $event, $rejectedFiles)">
<div class="row" ui-sortable="fileSortableOptions" ng-model="files" style="min-height: 150px;"> <div class="row upload-zone" ui-sortable="fileSortableOptions" ng-model="files">
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-center" ng-repeat="file in files"> <div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-center" ng-repeat="file in files">
<div class="thumbnail" ng-if="file.id"> <div class="thumbnail" ng-if="file.id">
<a ng-click="openFile(file)"> <a ng-click="openFile(file)">

View File

@ -164,6 +164,19 @@ input[readonly].share-link {
margin-right: auto; margin-right: auto;
} }
// Drag & drop related
.bg-success { .bg-success {
background-color: #dff0d8; background-color: #dff0d8;
} }
.upload-zone {
min-height: 150px;
}
.thumbnail-checked {
background-color: #dff0d8;
}
.pointer {
cursor: pointer;
}