user.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. deleteRecord:function (event) {
  22. var self = this;
  23. if (event.context.get('userName') == App.get('router').getLoginName()) {
  24. App.ModalPopup.show({
  25. header:Em.I18n.t('admin.users.delete.yourself.header'),
  26. body:Em.I18n.t('admin.users.delete.yourself.message'),
  27. onPrimary:function (event) {
  28. this.hide();
  29. },
  30. secondary:false
  31. });
  32. return;
  33. }
  34. ;
  35. App.ModalPopup.show({
  36. header:Em.I18n.t('admin.users.delete.header').format(event.context.get('userName')),
  37. body:Em.I18n.t('question.sure'),
  38. primary:Em.I18n.t('yes'),
  39. secondary:Em.I18n.t('no'),
  40. onPrimary:function () {
  41. self.sendCommandToServer('/users/' + event.context.get("userName"),"DELETE" ,{},
  42. function (requestId) {
  43. if (!requestId) {
  44. return;
  45. }
  46. event.context.deleteRecord();
  47. try {
  48. App.store.commit()
  49. } catch (err) {
  50. }
  51. })
  52. this.hide();
  53. },
  54. onSecondary:function () {
  55. this.hide();
  56. }
  57. });
  58. },
  59. sendCommandToServer : function(url, method, postData, callback){
  60. var url = (App.testMode) ?
  61. '/data/wizard/deploy/poll_1.json' : //content is the same as ours
  62. '/api/' + url;
  63. var method = App.testMode ? 'GET' : method;
  64. $.ajax({
  65. type: method,
  66. url: url,
  67. data: JSON.stringify(postData),
  68. dataType: 'json',
  69. timeout: 5000,
  70. success: function(data){
  71. if(data && data.Requests){
  72. callback(data.Requests.id);
  73. } else{
  74. callback(null);
  75. console.log('cannot get request id from ', data);
  76. }
  77. },
  78. error: function (request, ajaxOptions, error) {
  79. //do something
  80. callback(null);
  81. console.log('error on change component host status')
  82. },
  83. statusCode: require('data/statusCodes')
  84. });
  85. }
  86. })