user.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 (success) {
  43. if (!success) {
  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. App.apiPrefix + 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: App.timeout,
  70. success: function(data){
  71. callback(true);
  72. },
  73. error: function (request, ajaxOptions, error) {
  74. //do something
  75. callback(false);
  76. console.log('error on change component host status')
  77. },
  78. statusCode: require('data/statusCodes')
  79. });
  80. }
  81. })