Work on JavaScript coding style.

This commit is contained in:
Norman Jäckel 2016-02-16 00:56:56 +01:00
parent 40a3d4534e
commit 75f4a2e62d
9 changed files with 71 additions and 50 deletions

View File

@ -84,13 +84,19 @@ gulp.task('tinymce-i18n', function () {
'bower_components/tinymce-i18n/langs/pt_PT.js', 'bower_components/tinymce-i18n/langs/pt_PT.js',
]) ])
.pipe(rename(function (path) { .pipe(rename(function (path) {
if (path.basename === 'pt_PT') {path.basename = 'pt'} if (path.basename === 'fr_FR') {
if (path.basename === 'fr_FR') {path.basename = 'fr'} path.basename = 'fr';
} else if (path.basename === 'pt_PT') {
path.basename = 'pt';
}
})) }))
.pipe(gulpif(argv.production, uglify())) .pipe(gulpif(argv.production, uglify()))
.pipe(gulp.dest(path.join(output_directory, 'tinymce', 'i18n'))); .pipe(gulp.dest(path.join(output_directory, 'tinymce', 'i18n')));
}); });
// Combines all TinyMCE related tasks.
gulp.task('tinymce', ['tinymce-skins', 'tinymce-i18n'], function () {});
// Compiles translation files (*.po) to *.json and saves them in the directory // Compiles translation files (*.po) to *.json and saves them in the directory
// openslides/static/i18n/. // openslides/static/i18n/.
gulp.task('translations', function () { gulp.task('translations', function () {
@ -102,7 +108,7 @@ gulp.task('translations', function () {
}); });
// Gulp default task. Runs all other tasks before. // Gulp default task. Runs all other tasks before.
gulp.task('default', ['js-libs', 'css-libs', 'fonts-libs', 'tinymce-skins', 'tinymce-i18n', 'translations'], function () {}); gulp.task('default', ['js-libs', 'css-libs', 'fonts-libs', 'tinymce', 'translations'], function () {});
/** /**
@ -123,7 +129,13 @@ gulp.task('pot', function () {
// Checks JavaScript using JSHint // Checks JavaScript using JSHint
gulp.task('jshint', function () { gulp.task('jshint', function () {
return gulp.src([ 'gulpfile.js', path.join( 'openslides', '*', 'static', '**', '*.js' ) ]) return gulp.src([
'gulpfile.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

@ -279,7 +279,7 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda'])
if (action == 'remove') { if (action == 'remove') {
return ($.inArray(operator.user.id, nextUsers) != -1); return ($.inArray(operator.user.id, nextUsers) != -1);
} }
} };
// begin speech of selected/next speaker // begin speech of selected/next speaker
$scope.beginSpeech = function (speakerId) { $scope.beginSpeech = function (speakerId) {
@ -304,12 +304,12 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda'])
}; };
// gets speech duration of selected speaker in seconds // gets speech duration of selected speaker in seconds
$scope.getDuration = function (speaker) { $scope.getDuration = function (speaker) {
var beginTimestamp = new Date(speaker.begin_time).getTime() var beginTimestamp = new Date(speaker.begin_time).getTime();
var endTimestamp = new Date(speaker.end_time).getTime() var endTimestamp = new Date(speaker.end_time).getTime();
// calculate duration in seconds // calculate duration in seconds
return Math.floor((endTimestamp - beginTimestamp) / 1000); return Math.floor((endTimestamp - beginTimestamp) / 1000);
} };
// save reordered list of speakers // save reordered list of speakers
$scope.treeOptions = { $scope.treeOptions = {
dropped: function (event) { dropped: function (event) {
@ -387,7 +387,7 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda'])
// *** CSV import *** // *** CSV import ***
// set initial data for csv import // set initial data for csv import
$scope.items = [] $scope.items = [];
$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'];
@ -494,7 +494,7 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda'])
element.href = 'data:text/csv;charset=utf-8,' + csvString; element.href = 'data:text/csv;charset=utf-8,' + csvString;
element.download = 'agenda-example.csv'; element.download = 'agenda-example.csv';
element.target = '_blank'; element.target = '_blank';
} };
} }
]); ]);

View File

@ -67,7 +67,7 @@ angular.module('OpenSlidesApp.assignments', [])
} }
} }
}, },
}) });
} }
]) ])
@ -131,7 +131,7 @@ angular.module('OpenSlidesApp.assignments', [])
} }
} }
}, },
}) });
} }
]) ])
@ -148,7 +148,7 @@ angular.module('OpenSlidesApp.assignments', [])
} }
} }
} }
}) });
} }
]) ])

View File

@ -99,8 +99,9 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
return { return {
// ngDialog for assignment form // ngDialog for assignment form
getDialog: function (assignment) { getDialog: function (assignment) {
var resolve;
if (assignment) { if (assignment) {
var resolve = { resolve = {
assignment: function() { assignment: function() {
return assignment; return assignment;
}, },
@ -116,7 +117,7 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
closeByEscape: false, closeByEscape: false,
closeByDocument: false, closeByDocument: false,
resolve: (resolve) ? resolve : null resolve: (resolve) ? resolve : null
} };
}, },
// angular-formly fields for assignment form // angular-formly fields for assignment form
getFormFields: function () { getFormFields: function () {
@ -162,7 +163,7 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
hide: !operator.hasPerms('assignments.can_manage') hide: !operator.hasPerms('assignments.can_manage')
}]; }];
} }
} };
} }
]) ])
@ -195,9 +196,9 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
assignment.description, assignment.description,
$scope.phases[assignment.phase].display_name, $scope.phases[assignment.phase].display_name,
_.map(assignment.assignment_related_users, _.map(assignment.assignment_related_users,
function (candidate) {return candidate.user.get_short_name()}).join(" "), function (candidate) {return candidate.user.get_short_name();}).join(" "),
].join(" "); ].join(" ");
} };
// open new/edit dialog // open new/edit dialog
$scope.openDialog = function (assignment) { $scope.openDialog = function (assignment) {
@ -338,13 +339,13 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
$scope.updatePhase = function (phase_id) { $scope.updatePhase = function (phase_id) {
assignment.phase = phase_id; assignment.phase = phase_id;
Assignment.save(assignment); Assignment.save(assignment);
} };
// create new ballot // create new ballot
$scope.createBallot = function () { $scope.createBallot = function () {
$http.post('/rest/assignments/assignment/' + assignment.id + '/create_poll/') $http.post('/rest/assignments/assignment/' + assignment.id + '/create_poll/')
.success(function(data){ .success(function(data){
$scope.alert.show = false; $scope.alert.show = false;
if (assignment.phase == 0) { if (assignment.phase === 0) {
$scope.updatePhase(1); $scope.updatePhase(1);
} }
}) })
@ -355,7 +356,7 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
// delete ballot // delete ballot
$scope.deleteBallot = function (poll) { $scope.deleteBallot = function (poll) {
poll.DSDestroy(); poll.DSDestroy();
} };
// edit poll dialog // edit poll dialog
$scope.editPollDialog = function (poll, ballot) { $scope.editPollDialog = function (poll, ballot) {
ngDialog.open({ ngDialog.open({
@ -396,8 +397,13 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
if (reverse) { if (reverse) {
$http.delete( $http.delete(
'/rest/assignments/assignment/' + assignment.id + '/mark_elected/', '/rest/assignments/assignment/' + assignment.id + '/mark_elected/',
{headers: {'Content-Type': 'application/json'}, {
data: JSON.stringify({user: user})}) headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify({user: user})
}
);
} else { } else {
$http.post('/rest/assignments/assignment/' + assignment.id + '/mark_elected/', {'user': user}) $http.post('/rest/assignments/assignment/' + assignment.id + '/mark_elected/', {'user': user})
.then(function(success) { .then(function(success) {
@ -414,7 +420,9 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
}; };
// Just mark some vote value strings for translation. // Just mark some vote value strings for translation.
gettext('Yes'), gettext('No'), gettext('Abstain'); gettext('Yes');
gettext('No');
gettext('Abstain');
} }
]) ])
@ -518,8 +526,9 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
// add dynamic form fields // add dynamic form fields
assignmentpoll.options.forEach(function(option) { assignmentpoll.options.forEach(function(option) {
var defaultValue;
if (assignmentpoll.yesnoabstain) { if (assignmentpoll.yesnoabstain) {
var defaultValue = { defaultValue = {
'yes': '', 'yes': '',
'no': '', 'no': '',
'abstain': '' 'abstain': ''
@ -565,7 +574,6 @@ angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments'])
defaultValue: defaultValue.abstain defaultValue: defaultValue.abstain
}); });
} else { } else {
var defaultValue;
if (option.votes.length) { if (option.votes.length) {
defaultValue = option.votes[0].weight; defaultValue = option.votes[0].weight;
} }

View File

@ -99,7 +99,7 @@ angular.module('OpenSlidesApp.core', [
if (language.code == current) if (language.code == current)
language.selected = true; language.selected = true;
}); });
return languages return languages;
}, },
// get detected browser language code // get detected browser language code
getBrowserLanguage: function () { getBrowserLanguage: function () {
@ -125,7 +125,7 @@ angular.module('OpenSlidesApp.core', [
}); });
return languages; return languages;
} }
} };
} }
]) ])
@ -157,7 +157,7 @@ angular.module('OpenSlidesApp.core', [
} }
}); });
} }
} };
} }
]) ])
@ -425,7 +425,7 @@ angular.module('OpenSlidesApp.core', [
return Array.prototype.filter.call(array, function (item) { return Array.prototype.filter.call(array, function (item) {
return getFilterString(item).toLowerCase().indexOf(string.toLowerCase()) > -1; return getFilterString(item).toLowerCase().indexOf(string.toLowerCase()) > -1;
}); });
} };
} }
]) ])

View File

@ -259,7 +259,7 @@ angular.module('OpenSlidesApp.core.site', [
controller: 'CustomslideUpdateCtrl', controller: 'CustomslideUpdateCtrl',
className: 'ngdialog-theme-default wide-form', className: 'ngdialog-theme-default wide-form',
resolve: { resolve: {
customslide: function() {return Customslide.find($stateParams.id) } customslide: function() {return Customslide.find($stateParams.id);}
}, },
preCloseCallback: function() { preCloseCallback: function() {
$state.go('core.customslide.detail', {customslide: $stateParams.id}); $state.go('core.customslide.detail', {customslide: $stateParams.id});
@ -385,7 +385,7 @@ angular.module('OpenSlidesApp.core.site', [
'link image charmap table | code preview fullscreen' 'link image charmap table | code preview fullscreen'
}; };
} }
} };
} }
]) ])
@ -424,7 +424,7 @@ angular.module('OpenSlidesApp.core.site', [
$scope.reset = function () { $scope.reset = function () {
$scope.value = $scope.default_value; $scope.value = $scope.default_value;
$scope.save(field.key, $scope.value); $scope.save(field.key, $scope.value);
} };
} }
}; };
} }
@ -502,7 +502,7 @@ angular.module('OpenSlidesApp.core.site', [
$scope.search = function(query) { $scope.search = function(query) {
$scope.query = ''; $scope.query = '';
$state.go('search', {q: query}); $state.go('search', {q: query});
} };
} }
]) ])
// Search Controller // Search Controller
@ -523,9 +523,9 @@ angular.module('OpenSlidesApp.core.site', [
data.urlParam = {id: element.id}; data.urlParam = {id: element.id};
$scope.results.push(data); $scope.results.push(data);
}); });
}) });
}); });
} };
// run search with get parameter from url // run search with get parameter from url
if ($stateParams.q) { if ($stateParams.q) {
@ -551,7 +551,7 @@ angular.module('OpenSlidesApp.core.site', [
customslide: function(Customslide) {return Customslide.find(customslide.id);} customslide: function(Customslide) {return Customslide.find(customslide.id);}
}; };
} }
resolve.mediafiles = function(Mediafile) {return Mediafile.findAll();} resolve.mediafiles = function(Mediafile) {return Mediafile.findAll();};
return { return {
template: 'static/templates/core/customslide-form.html', template: 'static/templates/core/customslide-form.html',
controller: (customslide) ? 'CustomslideUpdateCtrl' : 'CustomslideCreateCtrl', controller: (customslide) ? 'CustomslideUpdateCtrl' : 'CustomslideCreateCtrl',
@ -559,7 +559,7 @@ angular.module('OpenSlidesApp.core.site', [
closeByEscape: false, closeByEscape: false,
closeByDocument: false, closeByDocument: false,
resolve: (resolve) ? resolve : null resolve: (resolve) ? resolve : null
} };
}, },
getFormFields: function () { getFormFields: function () {
var images = Mediafile.getAllImages(); var images = Mediafile.getAllImages();
@ -605,7 +605,7 @@ angular.module('OpenSlidesApp.core.site', [
}, },
]; ];
} }
} };
} }
]) ])
@ -999,7 +999,7 @@ angular.module('OpenSlidesApp.core.site', [
$scope.chatboxIsCollapsed = !$scope.chatboxIsCollapsed; $scope.chatboxIsCollapsed = !$scope.chatboxIsCollapsed;
NewChatMessages = []; NewChatMessages = [];
$scope.unreadMessages = NewChatMessages.length; $scope.unreadMessages = NewChatMessages.length;
} };
$scope.sendMessage = function () { $scope.sendMessage = function () {
angular.element('#messageSendButton').addClass('disabled'); angular.element('#messageSendButton').addClass('disabled');
angular.element('#messageInput').attr('disabled', ''); angular.element('#messageInput').attr('disabled', '');
@ -1027,7 +1027,7 @@ angular.module('OpenSlidesApp.core.site', [
$scope.unreadMessages = NewChatMessages.length; $scope.unreadMessages = NewChatMessages.length;
} }
} }
}) });
} }
]) ])

View File

@ -13,7 +13,7 @@ angular.module('OpenSlidesApp.mediafiles', [])
name: name, name: name,
useClass: jsDataModel, useClass: jsDataModel,
getAllImages: function () { getAllImages: function () {
var images = [] var images = [];
angular.forEach(this.getAll(), function(file) { angular.forEach(this.getAll(), function(file) {
if (file.is_image) { if (file.is_image) {
images.push({title: file.title, value: file.mediafileUrl}); images.push({title: file.title, value: file.mediafileUrl});

View File

@ -22,7 +22,7 @@ angular.module('OpenSlidesApp.mediafiles.projector', ['OpenSlidesApp.mediafiles'
mediafile.then(function(mediafile) { mediafile.then(function(mediafile) {
$scope.pdfName = mediafile.title; $scope.pdfName = mediafile.title;
$scope.pdfUrl = mediafile.mediafileUrl; $scope.pdfUrl = mediafile.mediafileUrl;
}) });
} }
]); ]);

View File

@ -40,7 +40,7 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
return User.findAll(); return User.findAll();
}, },
} }
}) });
} }
]) ])
@ -62,7 +62,7 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
$scope.reverse = false; $scope.reverse = false;
function updatePresentedMediafiles() { function updatePresentedMediafiles() {
var projectorElements = _.map(Projector.get(1).elements, function(element) { return element }); var projectorElements = _.map(Projector.get(1).elements, function(element) { return element; });
$scope.presentedMediafiles = _.filter(projectorElements, function (element) { $scope.presentedMediafiles = _.filter(projectorElements, function (element) {
return element.name === 'mediafiles/mediafile'; return element.name === 'mediafiles/mediafile';
}); });
@ -94,7 +94,7 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
mediafile.mediafile.name, mediafile.mediafile.name,
mediafile.uploader.get_short_name() mediafile.uploader.get_short_name()
].join(" "); ].join(" ");
} };
// open new/edit dialog // open new/edit dialog
$scope.openDialog = function (mediafile) { $scope.openDialog = function (mediafile) {
@ -242,7 +242,7 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
$scope.alert = {type: 'danger', msg: message, show: true}; $scope.alert = {type: 'danger', msg: message, show: true};
} }
); );
} };
} }
]) ])
@ -286,7 +286,7 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
$scope.alert = {type: 'danger', msg: message, show: true}; $scope.alert = {type: 'danger', msg: message, show: true};
} }
); );
} };
} }
]) ])
@ -301,8 +301,9 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
return { return {
// ngDialog for mediafile form // ngDialog for mediafile form
getDialog: function (mediafile) { getDialog: function (mediafile) {
var resolve;
if (mediafile) { if (mediafile) {
var resolve = { resolve = {
mediafile: function(Assignment) {return mediafile;} mediafile: function(Assignment) {return mediafile;}
}; };
} }
@ -313,7 +314,7 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
closeByEscape: false, closeByEscape: false,
closeByDocument: false, closeByDocument: false,
resolve: (resolve) ? resolve : null resolve: (resolve) ? resolve : null
} };
}, },
// upload selected file (used by create view only) // upload selected file (used by create view only)
uploadFile: function (mediafile) { uploadFile: function (mediafile) {