|
17 | 17 | var DataTypeModel = xtens.module("datatype").Model;
|
18 | 18 | var DataTypeCollection = xtens.module("datatype").List;
|
19 | 19 | var FileManager = xtens.module("filemanager");
|
| 20 | + var Group = xtens.module("group"); |
20 | 21 | var replaceUnderscoreAndCapitalize = xtens.module("utils").replaceUnderscoreAndCapitalize;
|
21 | 22 | var dateUtil = xtens.module("utils").date;
|
22 | 23 | var ModalDialog = xtens.module("xtensbootstrap").Views.ModalDialog;
|
|
694 | 695 | this.template = JST["views/templates/data-edit.ejs"];
|
695 | 696 | this.schemaView = null;
|
696 | 697 | this.dataTypes = options.dataTypes || [];
|
| 698 | + this.operators = options.operators ? options.operators : []; |
697 | 699 | // _.extend(this, options);
|
698 | 700 | if (options.data) {
|
699 | 701 | this.model = new Data.Model(options.data);
|
|
734 | 736 | * @description Backbone.stickit bindings
|
735 | 737 | */
|
736 | 738 | bindings: {
|
737 |
| - '#dataType': { |
| 739 | + '#data-type': { |
738 | 740 | observe: 'type',
|
739 | 741 | selectOptions: {
|
740 | 742 | collection: 'this.dataTypes',
|
|
762 | 764 | }
|
763 | 765 | },
|
764 | 766 |
|
| 767 | + '#owner': { |
| 768 | + observe: 'owner', |
| 769 | + initialize: function($el) { |
| 770 | + $el.select2({placeholder: i18n("please-select") }); |
| 771 | + }, |
| 772 | + selectOptions: { |
| 773 | + collection: function() { |
| 774 | + var coll = []; |
| 775 | + _.each(this.operators, function(op){ |
| 776 | + coll.push({label:op.lastName + ' ' + op.firstName ,value:op.id}); |
| 777 | + }); |
| 778 | + return coll; |
| 779 | + }, |
| 780 | + defaultOption: { |
| 781 | + label: '', |
| 782 | + value: null |
| 783 | + } |
| 784 | + }, |
| 785 | + onGet: function(val) { |
| 786 | + return val && val.id; |
| 787 | + } |
| 788 | + }, |
| 789 | + |
765 | 790 | '#date': {
|
766 | 791 | observe: 'date',
|
767 | 792 |
|
|
824 | 849 | var that = this;
|
825 | 850 | var metadata = this.schemaView.serialize(useFormattedNames);
|
826 | 851 | this.model.set("metadata", metadata);
|
| 852 | + this.model.get("owner").id ? this.model.set("owner", this.model.get("owner").id) : null; |
827 | 853 | // this.model.set("type", this.model.get("type").id); // trying to send only the id to permorf POST or PUT
|
828 | 854 | this.retrieveAndSetFiles();
|
829 | 855 | console.log(this.model);
|
|
856 | 882 | return false;
|
857 | 883 | },
|
858 | 884 |
|
| 885 | + setOwnerList: function () { |
| 886 | + var that = this, project, projectId; |
| 887 | + if ($('#data-type').val()) { |
| 888 | + var dataTypeSelected = _.parseInt($('#data-type').val()); |
| 889 | + projectId = _.find(this.dataTypes,{id:dataTypeSelected}).project; |
| 890 | + project = _.find(xtens.session.get('projects'), function (p) { |
| 891 | + return p.id === projectId; |
| 892 | + }); |
| 893 | + }else { |
| 894 | + project = _.find(xtens.session.get('projects'), function (p) { |
| 895 | + return p.name === xtens.session.get('activeProject'); |
| 896 | + }); |
| 897 | + } |
| 898 | + var groups = new Group.List(); |
| 899 | + |
| 900 | + var groupIds = _.compact(_.map(project.groups,function (g) { |
| 901 | + if ((g.privilegeLevel ==="wheel" || g.privilegeLevel ==="admin") ) { |
| 902 | + return g.id; |
| 903 | + } |
| 904 | + })); |
| 905 | + |
| 906 | + var groupsDeferred = groups.fetch({ |
| 907 | + data: $.param({where: {id: groupIds}, sort:'id ASC', limit:100, populate:['members']}) |
| 908 | + }); |
| 909 | + $.when(groupsDeferred).then(function(groupRes) { |
| 910 | + that.operators = _.isArray(groupRes) ?_.flatten(_.map(groupRes,'members')) :groupRes.members; |
| 911 | + var newColl = []; |
| 912 | + that.operators.forEach(function (op) { |
| 913 | + newColl.push({label:op.lastName + ' ' + op.firstName ,value:op.id}); |
| 914 | + }); |
| 915 | + var options = {selectOptions:{collection:newColl}}; |
| 916 | + Backbone.Stickit.getConfiguration($('#owner')).update($('#owner'),{},{},options); |
| 917 | + $('#owner').val({}).trigger("change"); |
| 918 | + }); |
| 919 | + }, |
859 | 920 | /**
|
860 | 921 | * @method
|
861 | 922 | * @name deleteDate
|
|
918 | 979 | },
|
919 | 980 |
|
920 | 981 | dataTypeOnChange: function() {
|
| 982 | + $('#owner').prop('disabled', false); |
| 983 | + this.setOwnerList(); |
921 | 984 | this.renderDataTypeSchema();
|
922 | 985 | },
|
923 | 986 |
|
|
1292 | 1355 |
|
1293 | 1356 | render: function() {
|
1294 | 1357 | this.$el.html(this.template({__: i18n}));
|
1295 |
| - $("#dataType").selectpicker(); |
| 1358 | + $("#data-type").selectpicker(); |
1296 | 1359 | this.$('form').parsley(parsleyOpts);
|
1297 | 1360 | this.dropzone = new Dropzone(this.$(".dropzone")[0], this.dropzoneOpts);
|
1298 | 1361 |
|
|
0 commit comments