diff --git a/openslides/assignments/static/js/assignments/site.js b/openslides/assignments/static/js/assignments/site.js
index 4b8a0587d..801513087 100644
--- a/openslides/assignments/static/js/assignments/site.js
+++ b/openslides/assignments/static/js/assignments/site.js
@@ -401,11 +401,10 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
.controller('AssignmentCreateCtrl', [
'$scope',
- '$state',
'Assignment',
'AssignmentForm',
'Agenda',
- function($scope, $state, Assignment, AssignmentForm, Agenda) {
+ function($scope, Assignment, AssignmentForm, Agenda) {
$scope.model = {};
// set default value for open posts form field
$scope.model.open_posts = 1;
@@ -435,12 +434,11 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
.controller('AssignmentUpdateCtrl', [
'$scope',
- '$state',
'Assignment',
'AssignmentForm',
'Agenda',
'assignment',
- function($scope, $state, Assignment, AssignmentForm, Agenda, assignment) {
+ function($scope, Assignment, AssignmentForm, Agenda, assignment) {
$scope.alert = {};
// set initial values for form model by create deep copy of assignment object
// so list/detail view is not updated while editing
@@ -487,12 +485,11 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
.controller('AssignmentPollUpdateCtrl', [
'$scope',
- '$state',
'gettextCatalog',
'AssignmentPoll',
'assignmentpoll',
'ballot',
- function($scope, $state, gettextCatalog, AssignmentPoll, assignmentpoll, ballot) {
+ function($scope, gettextCatalog, AssignmentPoll, assignmentpoll, ballot) {
// set initial values for form model
$scope.model = assignmentpoll;
$scope.ballot = ballot;
diff --git a/openslides/mediafiles/static/js/mediafiles/base.js b/openslides/mediafiles/static/js/mediafiles/base.js
index 8a645f877..2608e9ce9 100644
--- a/openslides/mediafiles/static/js/mediafiles/base.js
+++ b/openslides/mediafiles/static/js/mediafiles/base.js
@@ -23,6 +23,9 @@ angular.module('OpenSlidesApp.mediafiles', [])
var filename = this.mediafile.name;
return /\/(.+?)$/.exec(filename)[1];
}],
+ filetype: [function () {
+ return this.mediafile.type;
+ }],
title_or_filename: ['title', 'mediafile', function (title) {
return title || this.filename;
}]
diff --git a/openslides/mediafiles/static/js/mediafiles/site.js b/openslides/mediafiles/static/js/mediafiles/site.js
index 781301bf5..8536399d4 100644
--- a/openslides/mediafiles/static/js/mediafiles/site.js
+++ b/openslides/mediafiles/static/js/mediafiles/site.js
@@ -35,38 +35,25 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
resolve: {
mediafiles: function(Mediafile) {
return Mediafile.findAll();
- }
+ },
+ users: function(User) {
+ return User.findAll();
+ },
}
})
- .state('mediafiles.mediafile.create', {})
- .state('mediafiles.mediafile.detail', {
- url: '/{id:int}',
- abstract: true,
- resolve: {
- mediafile: function(Mediafile, $stateParams) {
- var id = $stateParams.id;
- var file = Mediafile.find(id);
- return file;
- }
- },
- template: "",
- })
- .state('mediafiles.mediafile.detail.update', {
- views: {
- '@mediafiles.mediafile': {}
- }
- });
}
])
.controller('MediafileListCtrl', [
'$scope',
'$http',
- '$timeout',
- 'Upload',
+ 'ngDialog',
'Mediafile',
- function($scope, $http, $timeout, Upload, Mediafile) {
+ 'MediafileForm',
+ 'User',
+ function($scope, $http, ngDialog, Mediafile, MediafileForm, User) {
Mediafile.bindAll({}, $scope, 'mediafiles');
+ User.bindAll({}, $scope, 'users');
// setup table sorting
$scope.sortColumn = 'title';
@@ -89,62 +76,158 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
].join(" ");
}
- // delete
+ // open new/edit dialog
+ $scope.openDialog = function (mediafile) {
+ ngDialog.open(MediafileForm.getDialog(mediafile));
+ };
+
+ // *** delete mode functions ***
+ $scope.isDeleteMode = false;
+ // check all checkboxes
+ $scope.checkAll = function () {
+ angular.forEach($scope.mediafiles, function (mediafile) {
+ mediafile.selected = $scope.selectedAll;
+ });
+ };
+ // uncheck all checkboxes if isDeleteMode is closed
+ $scope.uncheckAll = function () {
+ if (!$scope.isDeleteMode) {
+ $scope.selectedAll = false;
+ angular.forEach($scope.mediafiles, function (mediafile) {
+ mediafile.selected = false;
+ });
+ }
+ };
+ // delete all selected mediafiles
+ $scope.deleteMultiple = function () {
+ angular.forEach($scope.mediafiles, function (mediafile) {
+ if (mediafile.selected)
+ Mediafile.destroy(mediafile.id);
+ });
+ $scope.isDeleteMode = false;
+ $scope.uncheckAll();
+ };
+ // delete single mediafile
$scope.delete = function (mediafile) {
- //TODO: add confirm message
- Mediafile.destroy(mediafile.id).then(
- function(success) {
- //TODO: success message
- }
- );
+ Mediafile.destroy(mediafile.id);
};
}
])
.controller('MediafileCreateCtrl', [
'$scope',
- '$state',
- '$timeout',
- 'operator',
- 'Upload',
- function($scope, $state, $timeout, operator, Upload) {
+ 'MediafileForm',
+ 'User',
+ function($scope, MediafileForm, User) {
+ User.bindAll({}, $scope, 'users');
$scope.mediafile = {};
- $scope.save = uploadFile($timeout, $scope, $state, operator, Upload);
+ $scope.alert = {};
+ $scope.users = User.getAll();
+
+ // upload and save mediafile
+ $scope.save = function (mediafile) {
+ MediafileForm.uploadFile(mediafile).then(
+ function (success) {
+ $scope.closeThisDialog();
+ },
+ function (error) {
+ var message = '';
+ for (var e in error.data) {
+ message += e + ': ' + error.data[e] + ' ';
+ }
+ $scope.alert = {type: 'danger', msg: message, show: true};
+ }
+ );
+ }
}
])
.controller('MediafileUpdateCtrl', [
'$scope',
+ 'operator',
+ 'Mediafile',
+ 'User',
+ 'mediafile',
+ function($scope, operator, Mediafile, User, mediafile) {
+ User.bindAll({}, $scope, 'users');
+ $scope.alert = {};
+ $scope.users = User.getAll();
+
+ // set initial values for form model by create deep copy of motion object
+ // so list/detail view is not updated while editing
+ $scope.mediafile = angular.copy(mediafile);
+
+ // save mediafile
+ $scope.save = function (mediafile) {
+ // reset title and uploader_id if empty
+ if (!mediafile.title) {
+ mediafile.title = mediafile.filename;
+ }
+ if (!mediafile.uploader_id) {
+ mediafile.uploader_id = operator.user.id;
+ }
+ // inject the changed mediafile (copy) object back into DS store
+ Mediafile.inject(mediafile);
+ // save change mediafile object on server
+ Mediafile.save(mediafile, { method: 'PATCH' }).then(
+ function (success) {
+ $scope.closeThisDialog();
+ },
+ function (error) {
+ Mediafile.refresh(mediafile);
+ var message = '';
+ for (var e in error.data) {
+ message += e + ': ' + error.data[e] + ' ';
+ }
+ $scope.alert = {type: 'danger', msg: message, show: true};
+ }
+ );
+ }
+ }
+])
+
+// Service for mediafile form
+.factory('MediafileForm', [
'$state',
- '$timeout',
'operator',
'Upload',
- 'Mediafile',
- 'mediafile',
- function($scope, $state, $timeout, operator, Upload, Mediafile, mediafile) {
- $scope.mediafile = mediafile;
- $scope.save = uploadFile($timeout, $scope, $state, operator, Upload, mediafile);
+ 'gettextCatalog',
+ 'User',
+ function ($state, operator, Upload, gettextCatalog, User) {
+ return {
+ // ngDialog for mediafile form
+ getDialog: function (mediafile) {
+ if (mediafile) {
+ var resolve = {
+ mediafile: function(Assignment) {return mediafile;}
+ };
+ }
+ return {
+ template: 'static/templates/mediafiles/mediafile-form.html',
+ controller: (mediafile) ? 'MediafileUpdateCtrl' : 'MediafileCreateCtrl',
+ className: 'ngdialog-theme-default wide-form',
+ closeByEscape: false,
+ closeByDocument: false,
+ resolve: (resolve) ? resolve : null
+ }
+ },
+ // upload selected file (used by create view only)
+ uploadFile: function (mediafile) {
+ if (!mediafile.title) {
+ mediafile.title = mediafile.newFile.name;
+ }
+ if (!mediafile.uploader_id) {
+ mediafile.uploader_id = operator.user.id;
+ }
+ return Upload.upload({
+ url: '/rest/mediafiles/mediafile/',
+ method: 'POST',
+ data: {mediafile: mediafile.newFile, title: mediafile.title, uploader_id: mediafile.uploader_id}
+ });
+
+ }
+ };
}
]);
-function uploadFile($timeout, $scope, $state, operator, Upload, mediafile) {
- return function(file) {
- file.upload = Upload.upload({
- url: '/rest/mediafiles/mediafile/' + (mediafile ? mediafile.id : ''),
- method: mediafile ? 'PUT' : 'POST',
- data: {mediafile: file.newFile, title: file.title, uploader_id: operator.user.id}
- });
-
- file.upload.then(function (response) {
- $timeout(function () {
- file.result = response.data;
- $state.go('mediafiles.mediafile.list');
- });
- }, function (response) {
- if (response.status > 0)
- $scope.errorMsg = response.status + ': ' + response.data;
- });
- };
-}
-
}());
diff --git a/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html b/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html
index 8de05a479..6a2864fb7 100644
--- a/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html
+++ b/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html
@@ -1,42 +1,46 @@
-