Merge pull request #1999 from normanjaeckel/JSHint

Fixed coding style in some JS files. Fixed #1979.
This commit is contained in:
Emanuel Schütze 2016-02-24 11:08:21 +01:00
commit 8b5b53f26e
4 changed files with 142 additions and 114 deletions

View File

@ -132,9 +132,6 @@ gulp.task('jshint', function () {
return gulp.src([ return gulp.src([
'gulpfile.js', 'gulpfile.js',
path.join( 'openslides', '*', 'static', '**', '*.js' ), path.join( 'openslides', '*', 'static', '**', '*.js' ),
'!' + path.join( 'openslides', 'users', 'static', 'js', 'users', 'site.js' ),
'!' + path.join( 'openslides', 'motions', 'static', 'js', 'motions', 'base.js' ),
'!' + path.join( 'openslides', 'motions', 'static', 'js', 'motions', 'site.js' ),
]) ])
.pipe(jshint()) .pipe(jshint())
.pipe(jshint.reporter('default')); .pipe(jshint.reporter('default'));

View File

@ -14,11 +14,11 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users'])
var states = []; var states = [];
_.forEach(this.next_states_id, function (stateId) { _.forEach(this.next_states_id, function (stateId) {
states.push(DS.get('motions/workflowstate', stateId)); states.push(DS.get('motions/workflowstate', stateId));
}) });
return states; return states;
} }
} }
}) });
} }
]) ])
@ -38,7 +38,7 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users'])
} }
} }
} }
}) });
} }
]) ])
@ -129,7 +129,7 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users'])
index = this.versions.length - 1; index = this.versions.length - 1;
} else { } else {
index = _.findIndex(this.versions, function (element) { index = _.findIndex(this.versions, function (element) {
return element.id == versionId return element.id == versionId;
}); });
} }
return this.versions[index]; return this.versions[index];
@ -169,30 +169,44 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users'])
*/ */
switch (action) { switch (action) {
case 'see': case 'see':
return (operator.hasPerms('motions.can_see') && return (
(!this.state.required_permission_to_see || operator.hasPerms('motions.can_see') &&
(
!this.state.required_permission_to_see ||
operator.hasPerms(this.state.required_permission_to_see) || operator.hasPerms(this.state.required_permission_to_see) ||
(operator.user in this.submitters))); (operator.user in this.submitters)
)
);
case 'update': case 'update':
return (operator.hasPerms('motions.can_manage') || return (
(($.inArray(operator.user, this.submitters) != -1) && operator.hasPerms('motions.can_manage') ||
this.state.allow_submitter_edit)); (
($.inArray(operator.user, this.submitters) != -1) &&
this.state.allow_submitter_edit
)
);
case 'quickedit': case 'quickedit':
return operator.hasPerms('motions.can_manage'); return operator.hasPerms('motions.can_manage');
case 'delete': case 'delete':
return operator.hasPerms('motions.can_manage'); return operator.hasPerms('motions.can_manage');
case 'create_poll': case 'create_poll':
return (operator.hasPerms('motions.can_manage') && return (
this.state.allow_create_poll); operator.hasPerms('motions.can_manage') &&
this.state.allow_create_poll
);
case 'support': case 'support':
return (operator.hasPerms('motions.can_support') && return (
operator.hasPerms('motions.can_support') &&
this.state.allow_support && this.state.allow_support &&
Config.get('motions_min_supporters').value > 0 && Config.get('motions_min_supporters').value > 0 &&
!($.inArray(operator.user, this.submitters) != -1) && ($.inArray(operator.user, this.submitters) == -1) &&
!($.inArray(operator.user, this.supporters) != -1)); ($.inArray(operator.user, this.supporters) == -1)
);
case 'unsupport': case 'unsupport':
return (this.state.allow_support && return (
($.inArray(operator.user, this.supporters) != -1)); this.state.allow_support &&
($.inArray(operator.user, this.supporters) != -1)
);
case 'change_state': case 'change_state':
return operator.hasPerms('motions.can_manage'); return operator.hasPerms('motions.can_manage');
case 'reset_state': case 'reset_state':
@ -272,35 +286,35 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users'])
'gettext', 'gettext',
function (gettext) { function (gettext) {
// workflow 1 // workflow 1
gettext('Simple Workflow') gettext('Simple Workflow');
gettext('submitted') gettext('submitted');
gettext('accepted') gettext('accepted');
gettext('Accept') gettext('Accept');
gettext('rejected') gettext('rejected');
gettext('Reject') gettext('Reject');
gettext('not decided') gettext('not decided');
gettext('Do not decide') gettext('Do not decide');
// workflow 2 // workflow 2
gettext('Complex Workflow') gettext('Complex Workflow');
gettext('published') gettext('published');
gettext('permitted') gettext('permitted');
gettext('Permit') gettext('Permit');
gettext('accepted') gettext('accepted');
gettext('Accept') gettext('Accept');
gettext('rejected') gettext('rejected');
gettext('Reject') gettext('Reject');
gettext('withdrawed') gettext('withdrawed');
gettext('Withdraw') gettext('Withdraw');
gettext('adjourned') gettext('adjourned');
gettext('Adjourn') gettext('Adjourn');
gettext('not concerned') gettext('not concerned');
gettext('Do not concern') gettext('Do not concern');
gettext('commited a bill') gettext('commited a bill');
gettext('Commit a bill') gettext('Commit a bill');
gettext('needs review') gettext('needs review');
gettext('Needs review') gettext('Needs review');
gettext('rejected (not authorized)') gettext('rejected (not authorized)');
gettext('Reject (not authorized)') gettext('Reject (not authorized)');
} }
]); ]);

View File

@ -164,7 +164,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
return { return {
// ngDialog for motion form // ngDialog for motion form
getDialog: function (motion) { getDialog: function (motion) {
var resolve = {} var resolve = {};
if (motion) { if (motion) {
resolve = { resolve = {
motion: function() { motion: function() {
@ -175,7 +175,9 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
} }
}; };
} }
resolve.mediafiles = function(Mediafile) {return Mediafile.findAll();} resolve.mediafiles = function (Mediafile) {
return Mediafile.findAll();
};
return { return {
template: 'static/templates/motions/motion-form.html', template: 'static/templates/motions/motion-form.html',
controller: (motion) ? 'MotionUpdateCtrl' : 'MotionCreateCtrl', controller: (motion) ? 'MotionUpdateCtrl' : 'MotionCreateCtrl',
@ -183,7 +185,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
closeByEscape: false, closeByEscape: false,
closeByDocument: false, closeByDocument: false,
resolve: (resolve) ? resolve : null resolve: (resolve) ? resolve : null
} };
}, },
// angular-formly fields for motion form // angular-formly fields for motion form
getFormFields: function () { getFormFields: function () {
@ -341,7 +343,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
hideExpression: '!model.more', hideExpression: '!model.more',
}]; }];
} }
} };
} }
]) ])
@ -404,7 +406,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
} }
}]; }];
} }
} };
} }
]) ])
@ -439,22 +441,36 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
}; };
// define custom search filter string // define custom search filter string
$scope.getFilterString = function (motion) { $scope.getFilterString = function (motion) {
var category = '';
if (motion.category) { if (motion.category) {
var category = motion.category.name; category = motion.category.name;
} else {
var category = ''
} }
return [ return [
motion.identifier, motion.identifier,
motion.getTitle(), motion.getTitle(),
motion.getText(), motion.getText(),
motion.getReason(), motion.getReason(),
_.map(motion.submitters, function (submitter) {return submitter.get_short_name()}).join(" "), _.map(
_.map(motion.supporters, function (supporter) {return supporter.get_short_name()}).join(" "), motion.submitters,
_.map(motion.tags, function (tag) {return tag.name}).join(" "), function (submitter) {
category return submitter.get_short_name();
].join(" ");
} }
).join(" "),
_.map(
motion.supporters,
function (supporter) {
return supporter.get_short_name();
}
).join(" "),
_.map(
motion.tags,
function (tag) {
return tag.name;
}
).join(" "),
category,
].join(" ");
};
// collect all states of all workflows // collect all states of all workflows
// TODO: regard workflows only which are used by motions // TODO: regard workflows only which are used by motions
@ -462,7 +478,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
var workflows = Workflow.getAll(); var workflows = Workflow.getAll();
angular.forEach(workflows, function (workflow) { angular.forEach(workflows, function (workflow) {
if (workflows.length > 1) { if (workflows.length > 1) {
var wf = {} var wf = {};
wf.name = workflow.name; wf.name = workflow.name;
wf.workflowSeparator = "-"; wf.workflowSeparator = "-";
$scope.states.push(wf); $scope.states.push(wf);
@ -565,23 +581,23 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
// support // support
$scope.support = function () { $scope.support = function () {
$http.post('/rest/motions/motion/' + motion.id + '/support/'); $http.post('/rest/motions/motion/' + motion.id + '/support/');
} };
// unsupport // unsupport
$scope.unsupport = function () { $scope.unsupport = function () {
$http.delete('/rest/motions/motion/' + motion.id + '/support/'); $http.delete('/rest/motions/motion/' + motion.id + '/support/');
} };
// update state // update state
$scope.updateState = function (state_id) { $scope.updateState = function (state_id) {
$http.put('/rest/motions/motion/' + motion.id + '/set_state/', {'state': state_id}); $http.put('/rest/motions/motion/' + motion.id + '/set_state/', {'state': state_id});
} };
// reset state // reset state
$scope.reset_state = function (state_id) { $scope.reset_state = function (state_id) {
$http.put('/rest/motions/motion/' + motion.id + '/set_state/', {}); $http.put('/rest/motions/motion/' + motion.id + '/set_state/', {});
} };
// create poll // create poll
$scope.create_poll = function () { $scope.create_poll = function () {
$http.post('/rest/motions/motion/' + motion.id + '/create_poll/', {}); $http.post('/rest/motions/motion/' + motion.id + '/create_poll/', {});
} };
// open poll update dialog // open poll update dialog
$scope.openPollDialog = function (poll, voteNumber) { $scope.openPollDialog = function (poll, voteNumber) {
ngDialog.open({ ngDialog.open({
@ -603,11 +619,11 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
// delete poll // delete poll
$scope.delete_poll = function (poll) { $scope.delete_poll = function (poll) {
poll.DSDestroy(); poll.DSDestroy();
} };
// show specific version // show specific version
$scope.showVersion = function (version) { $scope.showVersion = function (version) {
$scope.version = version.id; $scope.version = version.id;
} };
// permit specific version // permit specific version
$scope.permitVersion = function (version) { $scope.permitVersion = function (version) {
$http.put('/rest/motions/motion/' + motion.id + '/manage_version/', $http.put('/rest/motions/motion/' + motion.id + '/manage_version/',
@ -615,7 +631,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
.then(function(success) { .then(function(success) {
$scope.version = version.id; $scope.version = version.id;
}); });
} };
// delete specific version // delete specific version
$scope.deleteVersion = function (version) { $scope.deleteVersion = function (version) {
$http.delete('/rest/motions/motion/' + motion.id + '/manage_version/', $http.delete('/rest/motions/motion/' + motion.id + '/manage_version/',
@ -624,7 +640,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
.then(function(success) { .then(function(success) {
$scope.version = motion.active_version; $scope.version = motion.active_version;
}); });
} };
} }
]) ])
@ -816,7 +832,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
'User', 'User',
function($scope, gettext, Category, Motion, User) { function($scope, gettext, Category, Motion, User) {
// set initial data for csv import // set initial data for csv import
$scope.motions = [] $scope.motions = [];
$scope.separator = ','; $scope.separator = ',';
$scope.encoding = 'UTF-8'; $scope.encoding = 'UTF-8';
$scope.encodingOptions = ['UTF-8', 'ISO-8859-1']; $scope.encodingOptions = ['UTF-8', 'ISO-8859-1'];
@ -845,7 +861,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
angular.forEach($scope.csv.result, function (motion) { angular.forEach($scope.csv.result, function (motion) {
if (motion.identifier) { if (motion.identifier) {
motion.identifier = motion.identifier.replace(quotionRe, '$1'); motion.identifier = motion.identifier.replace(quotionRe, '$1');
if (motion.identifier != '') { if (motion.identifier !== '') {
// All motion objects are already loaded via the resolve statement from ui-router. // All motion objects are already loaded via the resolve statement from ui-router.
var motions = Motion.getAll(); var motions = Motion.getAll();
if (_.find(motions, function (item) { if (_.find(motions, function (item) {
@ -879,7 +895,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
// submitter // submitter
if (motion.submitter) { if (motion.submitter) {
motion.submitter = motion.submitter.replace(quotionRe, '$1'); motion.submitter = motion.submitter.replace(quotionRe, '$1');
if (motion.submitter != '') { if (motion.submitter !== '') {
// All user objects are already loaded via the resolve statement from ui-router. // All user objects are already loaded via the resolve statement from ui-router.
var users = User.getAll(); var users = User.getAll();
angular.forEach(users, function (user) { angular.forEach(users, function (user) {
@ -890,13 +906,13 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
}); });
} }
} }
if (motion.submitter && motion.submitter != '' && !motion.submitters_id) { if (motion.submitter && motion.submitter !== '' && !motion.submitters_id) {
motion.submitter_create = gettext('New participant will be created.'); motion.submitter_create = gettext('New participant will be created.');
} }
// category // category
if (motion.category) { if (motion.category) {
motion.category = motion.category.replace(quotionRe, '$1'); motion.category = motion.category.replace(quotionRe, '$1');
if (motion.category != '') { if (motion.category !== '') {
// All categore objects are already loaded via the resolve statement from ui-router. // All categore objects are already loaded via the resolve statement from ui-router.
var categories = Category.getAll(); var categories = Category.getAll();
angular.forEach(categories, function (category) { angular.forEach(categories, function (category) {
@ -908,7 +924,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
}); });
} }
} }
if (motion.category && motion.category != '' && !motion.category_id) { if (motion.category && motion.category !== '' && !motion.category_id) {
motion.category_create = gettext('New category will be created.'); motion.category_create = gettext('New category will be created.');
} }
$scope.motions.push(motion); $scope.motions.push(motion);
@ -927,7 +943,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
first_name: motion.submitter.substr(0, index), first_name: motion.submitter.substr(0, index),
last_name: motion.submitter.substr(index+1), last_name: motion.submitter.substr(index+1),
groups: [] groups: []
} };
User.create(user).then( User.create(user).then(
function(success) { function(success) {
// set new user id // set new user id
@ -940,7 +956,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
var category = { var category = {
name: motion.category, name: motion.category,
prefix: motion.category.charAt(0) prefix: motion.category.charAt(0)
} };
Category.create(category).then( Category.create(category).then(
function(success) { function(success) {
// set new category id // set new category id
@ -976,7 +992,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
element.href = 'data:text/csv;charset=utf-8,' + csvString; element.href = 'data:text/csv;charset=utf-8,' + csvString;
element.download = 'motions-example.csv'; element.download = 'motions-example.csv';
element.target = '_blank'; element.target = '_blank';
} };
} }
]) ])

View File

@ -242,8 +242,9 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
return { return {
// ngDialog for user form // ngDialog for user form
getDialog: function (user) { getDialog: function (user) {
var resolve;
if (user) { if (user) {
var resolve = { resolve = {
user: function(User) {return User.find(user.id);} user: function(User) {return User.find(user.id);}
}; };
} }
@ -254,7 +255,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
closeByEscape: false, closeByEscape: false,
closeByDocument: false, closeByDocument: false,
resolve: (resolve) ? resolve : null resolve: (resolve) ? resolve : null
} };
}, },
// angular-formly fields for user form // angular-formly fields for user form
getFormFields: function (hideOnCreateForm) { getFormFields: function (hideOnCreateForm) {
@ -372,7 +373,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
defaultValue: true defaultValue: true
}]; }];
} }
} };
} }
]) ])
@ -667,7 +668,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
// *** csv import *** // *** csv import ***
// set initial data for csv import // set initial data for csv import
$scope.users = [] $scope.users = [];
$scope.separator = ','; $scope.separator = ',';
$scope.encoding = 'UTF-8'; $scope.encoding = 'UTF-8';
$scope.encodingOptions = ['UTF-8', 'ISO-8859-1']; $scope.encodingOptions = ['UTF-8', 'ISO-8859-1'];
@ -726,7 +727,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
var csvGroups = user.groups.replace(quotionRe, '$1').split(","); var csvGroups = user.groups.replace(quotionRe, '$1').split(",");
user.groups = []; user.groups = [];
user.groupnames = []; user.groupnames = [];
if (csvGroups != '') { if (csvGroups !== '') {
// All group objects are already loaded via the resolve statement from ui-router. // All group objects are already loaded via the resolve statement from ui-router.
var allGroups = Group.getAll(); var allGroups = Group.getAll();
csvGroups.forEach(function(csvGroup) { csvGroups.forEach(function(csvGroup) {
@ -793,7 +794,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
element.href = 'data:text/csv;charset=utf-8,' + csvString; element.href = 'data:text/csv;charset=utf-8,' + csvString;
element.download = 'users-example.csv'; element.download = 'users-example.csv';
element.target = '_blank'; element.target = '_blank';
} };
} }
]) ])
@ -893,7 +894,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
msg: data.info_text msg: data.info_text
}); });
} }
}) });
// close alert function // close alert function
$scope.closeAlert = function(index) { $scope.closeAlert = function(index) {
$scope.alerts.splice(index, 1); $scope.alerts.splice(index, 1);
@ -934,35 +935,35 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'gettext', 'gettext',
function (gettext) { function (gettext) {
// agenda // agenda
gettext('Can see agenda') gettext('Can see agenda');
gettext('Can manage agenda') gettext('Can manage agenda');
gettext('Can see hidden items and time scheduling of agenda') gettext('Can see hidden items and time scheduling of agenda');
gettext('Can put oneself on the list of speakers') gettext('Can put oneself on the list of speakers');
// assignments // assignments
gettext('Can see elections') gettext('Can see elections');
gettext('Can nominate another participant') gettext('Can nominate another participant');
gettext('Can nominate oneself') gettext('Can nominate oneself');
gettext('Can manage elections') gettext('Can manage elections');
// core // core
gettext('Can see the projector') gettext('Can see the projector');
gettext('Can manage the projector') gettext('Can manage the projector');
gettext('Can see the front page') gettext('Can see the front page');
gettext('Can manage tags') gettext('Can manage tags');
gettext('Can manage configuration') gettext('Can manage configuration');
gettext('Can use the chat') gettext('Can use the chat');
// mediafiles // mediafiles
gettext('Can see the list of files') gettext('Can see the list of files');
gettext('Can upload files') gettext('Can upload files');
gettext('Can manage files') gettext('Can manage files');
// motions // motions
gettext('Can see motions') gettext('Can see motions');
gettext('Can create motions') gettext('Can create motions');
gettext('Can support motions') gettext('Can support motions');
gettext('Can manage motions') gettext('Can manage motions');
// users // users
gettext('Can see names of users') gettext('Can see names of users');
gettext('Can see extra data of users') gettext('Can see extra data of users');
gettext('Can manage users') gettext('Can manage users');
} }
]); ]);