user.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.UserModel = Em.Object.extend({
  20. userName:null,
  21. id:0
  22. });
  23. App.User = DS.Model.extend({
  24. userName:DS.attr('string'),
  25. admin:DS.attr('boolean'),
  26. password:DS.attr('string'),
  27. auditItems:DS.hasMany('App.ServiceAudit')
  28. });
  29. App.UserForm = App.Form.extend({
  30. className:App.User,
  31. fieldsOptions:[
  32. { name:"userName", displayName:"Username" },
  33. { name:"password", displayName:"Password", displayType:"password", disableRequiredOnExistent:true },
  34. { name:"passwordRetype", displayName:"Retype Password", displayType:"passwordRetype", disableRequiredOnExistent:true },
  35. { name:"admin", displayName:"Admin", displayType:"checkbox", isRequired:false }
  36. ],
  37. fields:[],
  38. disableUsername:function () {
  39. var field = this.getField("userName");
  40. if (field) field.set("disabled", this.get('isObjectNew') ? false : "disabled");
  41. }.observes('isObjectNew'),
  42. disableAdminCheckbox:function () {
  43. var object = this.get('object');
  44. var field = this.getField("admin");
  45. if (field) {
  46. field.set("disabled", object.get('userName') == App.get('router').getLoginName() ? "disabled" : false);
  47. }
  48. }.observes('isObjectNew')
  49. });
  50. App.User.FIXTURES = [
  51. {
  52. id:1,
  53. user_name:'admin',
  54. password:'admin',
  55. admin:1
  56. },
  57. {
  58. id:2,
  59. user_name:'vrossi',
  60. admin:1
  61. },
  62. {
  63. id:3,
  64. user_name:'casey.stoner',
  65. admin:0
  66. },
  67. {
  68. id:4,
  69. user_name:'danip',
  70. admin:0
  71. }
  72. ];