diff --git a/osmtm/static/js/project.edit.js b/osmtm/static/js/project.edit.js index 0645d718..0341bfea 100644 --- a/osmtm/static/js/project.edit.js +++ b/osmtm/static/js/project.edit.js @@ -54,6 +54,29 @@ $(document).ready(function() { }); }); +// taken from the great GeoJSON.io +function readAsText(f, callback) { + try { + var reader = new FileReader(); + reader.readAsText(f); + reader.onload = function(e) { + if (e.target && e.target.result) callback(null, e.target.result); + else callback({ + message: droppedFileCouldntBeLoadedI18n + }); + }; + reader.onerror = function(e) { + callback({ + message: droppedFileWasUnreadableI18n + }); + }; + } catch (e) { + callback({ + message: droppedFileWasUnreadableI18n + }); + } +} + function allowedUsersCrtl($scope) { $scope.allowed_users = allowed_users; @@ -82,6 +105,51 @@ function allowedUsersCrtl($scope) { } }); }); + + $('#user_import').click(function() { + $('input[name=user_import]').click(); + return false; + }); + + + $('input[name=user_import]').change(function() { + function addUserToProject(userToAdd) { + $.ajax({ + url: base_url + 'project/' + project_id + '/user/' + userToAdd, + type: 'PUT', + success: function(data) { + $scope.$apply(function() { + allowed_users[data.user.id] = data.user; + $scope.allowed_users = allowed_users; + }); + } + }); + } + + var file = $(this).val(); + if ((file.substr(-3) == 'txt') || (file.substr(-3) == 'csv')) { + readAsText($(this)[0].files[0], function(err, text) { + var lines = text.split(/\r\n|\n/); + var usersToAdd = []; + + for (var i=0; i <% @@ -394,6 +398,24 @@ geometry = loads(str(project.area.geometry.data)) +
+
+
${_('or')}
+
+
+
+
+
+ +<% + link = '%s' \ + % (_('Provide a .txt or .csv file of usernames separated by commas or lines.'), _('Import')) + text = _('${user_import_link} a txt or csv file of Tasking Manager usernames.', mapping={'user_import_link': link}) +%> + ${text|n} +
+
+
<% from osmtm.models import dumps