create.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.MainAdminUserCreateView = Em.View.extend({
  20. templateName: require('templates/main/admin/user/create'),
  21. userId: false,
  22. create: function(event){
  23. var parent_controller=this.get("controller").controllers.mainAdminUserController;
  24. var form = this.get("userForm");
  25. if(form.isValid()) {
  26. form.getField("userName").set('value', form.getField("userName").get('value').toLowerCase());
  27. if(form.getField("admin").get('value') === "" || form.getField("admin").get('value') == true) {
  28. form.getField("roles").set("value","admin,user");
  29. form.getField("admin").set("value","true");
  30. } else{
  31. form.getField("roles").set("value","user");
  32. }
  33. parent_controller.sendCommandToServer('/users/' + form.getField("userName").get('value'), "POST" , {
  34. Users: {
  35. password: form.getField("password").get('value'),
  36. roles: form.getField("roles").get('value')
  37. }
  38. }, function (success) {
  39. if (!success) {
  40. App.ModalPopup.show({
  41. header: Em.I18n.t('admin.users.addButton'),
  42. body: Em.I18n.t('admin.users.createError'),
  43. primary: 'Ok',
  44. secondary: null,
  45. onPrimary: function() {
  46. this.hide();
  47. }
  48. });
  49. return;
  50. }
  51. App.ModalPopup.show({
  52. header: Em.I18n.t('admin.users.addButton'),
  53. body: Em.I18n.t('admin.users.createSuccess'),
  54. primary: 'Ok',
  55. secondary: null,
  56. onPrimary: function() {
  57. this.hide();
  58. }
  59. });
  60. form.save();
  61. App.router.transitionTo("allUsers");
  62. })
  63. }
  64. },
  65. userForm: App.CreateUserForm.create({}),
  66. didInsertElement: function(){
  67. this.get('userForm').propertyDidChange('object');
  68. }
  69. });