diff --git a/openslides/core/static/js/core/site.js b/openslides/core/static/js/core/site.js index 6bb903410..2e0aefa52 100644 --- a/openslides/core/static/js/core/site.js +++ b/openslides/core/static/js/core/site.js @@ -611,27 +611,32 @@ angular.module('OpenSlidesApp.core.site', [ // Configure custom types formlyConfig.setType({ - name: 'editor', - extends: 'textarea', - templateUrl: 'static/templates/core/editor.html', + name: 'editor', + extends: 'textarea', + templateUrl: 'static/templates/core/editor.html', }); formlyConfig.setType({ - name: 'select-single', - extends: 'select', - templateUrl: 'static/templates/core/select-single.html' + name: 'select-single', + extends: 'select', + templateUrl: 'static/templates/core/select-single.html' }); formlyConfig.setType({ - name: 'select-multiple', - extends: 'select', - templateUrl: 'static/templates/core/select-multiple.html' + name: 'select-multiple', + extends: 'select', + templateUrl: 'static/templates/core/select-multiple.html' }); formlyConfig.setType({ - name: 'radio-buttons', - templateUrl: 'static/templates/core/radio-buttons.html', - wrapper: ['bootstrapHasError'], - defaultOptions: { - noFormControl: false - } + name: 'radio-buttons', + templateUrl: 'static/templates/core/radio-buttons.html', + wrapper: ['bootstrapHasError'], + defaultOptions: { + noFormControl: false + } + }); + formlyConfig.setType({ + name: 'file', + extends: 'input', + templateUrl: 'static/templates/core/file.html', }); } ]) diff --git a/openslides/core/static/templates/core/file.html b/openslides/core/static/templates/core/file.html new file mode 100644 index 000000000..a303b22d1 --- /dev/null +++ b/openslides/core/static/templates/core/file.html @@ -0,0 +1,2 @@ + + diff --git a/openslides/core/static/templates/search.html b/openslides/core/static/templates/search.html index 564af7ea5..b229c09a0 100644 --- a/openslides/core/static/templates/search.html +++ b/openslides/core/static/templates/search.html @@ -13,8 +13,9 @@
-
diff --git a/openslides/mediafiles/static/js/mediafiles/create.js b/openslides/mediafiles/static/js/mediafiles/create.js index bc28b5eea..ec29121ee 100644 --- a/openslides/mediafiles/static/js/mediafiles/create.js +++ b/openslides/mediafiles/static/js/mediafiles/create.js @@ -4,33 +4,44 @@ angular.module('OpenSlidesApp.mediafiles.create', [ 'OpenSlidesApp.mediafiles.forms', - //TODO: Add deps for User ]) .controller('MediafileCreateCtrl', [ '$scope', - 'User', 'MediafileForm', - function ($scope, User, MediafileForm) { - User.bindAll({}, $scope, 'users'); - $scope.mediafile = {}; + function ($scope, MediafileForm) { + $scope.model = {}; $scope.alert = {}; - $scope.users = User.getAll(); + $scope.formFields = MediafileForm.getFormFields(true); // 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] + ' '; + if (typeof mediafile.getFile === 'function') { + $scope.activeUpload = MediafileForm.uploadFile(mediafile).then( + function (success) { + $scope.closeThisDialog(); + }, + function (error) { + $scope.activeUpload = void 0; + var message = ''; + for (var e in error.data) { + message += e + ': ' + error.data[e] + ' '; + } + $scope.alert = {type: 'danger', msg: message, show: true}; + }, + function (progress) { + $scope.progress = parseInt(100.0 * progress.loaded / progress.total); } - $scope.alert = {type: 'danger', msg: message, show: true}; - } - ); + ); + } + }; + $scope.close = function () { + // TODO: abort() is not a function. But it is documented in the docs. + // See https://github.com/danialfarid/ng-file-upload/issues/1844 + /*if ($scope.activeUpload) { + $scope.activeUpload.abort(); + }*/ + $scope.closeThisDialog(); }; } ]); diff --git a/openslides/mediafiles/static/js/mediafiles/forms.js b/openslides/mediafiles/static/js/mediafiles/forms.js index 6855fb3e6..069ca682a 100644 --- a/openslides/mediafiles/static/js/mediafiles/forms.js +++ b/openslides/mediafiles/static/js/mediafiles/forms.js @@ -12,33 +12,29 @@ angular.module('OpenSlidesApp.mediafiles.forms', [ // Service for mediafile form .factory('MediafileForm', [ 'gettextCatalog', - '$state', 'Upload', 'operator', 'User', - function (gettextCatalog, $state, Upload, operator, User) { + function (gettextCatalog, Upload, operator, User) { return { // ngDialog for mediafile form getDialog: function (mediafile) { - var resolve; - if (mediafile) { - 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 + resolve: { + mediafileId: function () {return mediafile ? mediafile.id : void 0;} + }, }; }, // upload selected file (used by create view only) uploadFile: function (mediafile) { + var file = mediafile.getFile(); if (!mediafile.title) { - mediafile.title = mediafile.newFile.name; + mediafile.title = file.name; } if (!mediafile.uploader_id) { mediafile.uploader_id = operator.user.id; @@ -46,8 +42,56 @@ angular.module('OpenSlidesApp.mediafiles.forms', [ return Upload.upload({ url: '/rest/mediafiles/mediafile/', method: 'POST', - data: {mediafile: mediafile.newFile, title: mediafile.title, uploader_id: mediafile.uploader_id, hidden: mediafile.hidden} + data: {mediafile: file, title: mediafile.title, uploader_id: mediafile.uploader_id, hidden: mediafile.hidden} }); + }, + getFormFields: function (isCreateForm) { + return [ + { + key: 'newFile', + type: 'file', + templateOptions: { + label: gettextCatalog.getString('File'), + required: true, + change: function (model, files, event, rejectedFiles) { + var file = files ? files[0] : void 0; + model.getFile = function () { + return file; + }; + model.newFile = file ? file.name : void 0; + }, + }, + hide: !isCreateForm, + }, + { + key: 'title', + type: 'input', + templateOptions: { + label: gettextCatalog.getString('Title'), + }, + }, + { + key: 'hidden', + type: 'checkbox', + templateOptions: { + label: gettextCatalog.getString('Hidden'), + description: gettextCatalog.getString('This does not protect the ' + + 'file but hides it for non authorized users.'), + }, + hide: !operator.hasPerms('mediafiles.can_see_hidden'), + }, + { + key: 'uploader_id', + type: 'select-single', + templateOptions: { + label: gettextCatalog.getString('Uploader'), + options: User.getAll(), + ngOptions: 'option.id as option.full_name for option in to.options', + placeholder: gettextCatalog.getString('Select or search a participant ...') + }, + hide: !operator.hasPerms('mediafiles.can_manage') + }, + ]; } }; diff --git a/openslides/mediafiles/static/js/mediafiles/update.js b/openslides/mediafiles/static/js/mediafiles/update.js index 457e06357..c2ee31c32 100644 --- a/openslides/mediafiles/static/js/mediafiles/update.js +++ b/openslides/mediafiles/static/js/mediafiles/update.js @@ -12,15 +12,15 @@ angular.module('OpenSlidesApp.mediafiles.update', [ 'operator', 'User', 'Mediafile', - 'mediafile', - function ($scope, operator, User, Mediafile, mediafile) { - User.bindAll({}, $scope, 'users'); + 'mediafileId', + 'MediafileForm', + function ($scope, operator, User, Mediafile, mediafileId, MediafileForm) { $scope.alert = {}; - $scope.users = User.getAll(); + $scope.formFields = MediafileForm.getFormFields(); // 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); + $scope.model = angular.copy(Mediafile.get(mediafileId)); // save mediafile $scope.save = function (mediafile) { diff --git a/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html b/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html index 53d829f5a..9aaf158f6 100644 --- a/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html +++ b/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html @@ -1,59 +1,24 @@ -

Edit file

-

New file

+

Edit file

+

New file

-
+
{{ alert.msg }}
-
- -
- - - - -
{{ mediafile.filename }}
-
+ + + File too large + {{ picFile.size / 1000000|number:1}}MB: max {{ mediafile.mediafile.$errorParam}} - -
- - -
+ + {{ progress }}% + - -
- -

- This does not protect the file but hides it for non authorized users. -

-
- - -
- - -
- - File too large - {{ picFile.size / 1000000|number:1}}MB: max {{ mediafile.mediafile.$errorParam}} - - - + + +