user.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.MainAdminUserController = Em.Controller.extend({
  20. name:'mainAdminUserController',
  21. /**
  22. * send request to the server to delete user if selected user is not current user
  23. * @param event
  24. */
  25. deleteRecord:function (event) {
  26. var self = this;
  27. if (event.context.get('userName') == App.get('router').getLoginName()) {
  28. App.ModalPopup.show({
  29. header:Em.I18n.t('admin.users.delete.yourself.header'),
  30. body:Em.I18n.t('admin.users.delete.yourself.message'),
  31. onPrimary:function (event) {
  32. this.hide();
  33. },
  34. secondary:false
  35. });
  36. return;
  37. }
  38. App.ModalPopup.show({
  39. header:Em.I18n.t('admin.users.delete.header').format(event.context.get('userName')),
  40. body:Em.I18n.t('question.sure').format(''),
  41. primary:Em.I18n.t('yes'),
  42. secondary:Em.I18n.t('no'),
  43. onPrimary:function () {
  44. self.sendCommandToServer('/users/' + event.context.get("userName"), "DELETE" ,{},
  45. function (success) {
  46. if (!success) {
  47. return;
  48. }
  49. event.context.deleteRecord();
  50. try {
  51. App.store.commit()
  52. } catch (err) {
  53. }
  54. })
  55. this.hide();
  56. },
  57. onSecondary:function () {
  58. this.hide();
  59. }
  60. });
  61. },
  62. /**
  63. * send request to the server and call callback function with true if request was success or false if request was failed
  64. * @param url
  65. * @param method
  66. * @param postData
  67. * @param callback
  68. */
  69. sendCommandToServer : function(url, method, postData, callback){
  70. if (App.testMode) {
  71. url = '/data/users/users.json';
  72. method = 'GET';
  73. postData = undefined;
  74. } else {
  75. url = App.apiPrefix + url;
  76. }
  77. $.ajax({
  78. type: method,
  79. url: url,
  80. data: JSON.stringify(postData),
  81. dataType: 'json',
  82. timeout: App.timeout,
  83. success: function(data){
  84. callback(true, '');
  85. },
  86. error: function (request, ajaxOptions, error) {
  87. callback(false, error);
  88. console.log('error on change component host status')
  89. },
  90. statusCode: require('data/statusCodes')
  91. });
  92. }
  93. })