edit_user.mako 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. ## Licensed to Cloudera, Inc. under one
  2. ## or more contributor license agreements. See the NOTICE file
  3. ## distributed with this work for additional information
  4. ## regarding copyright ownership. Cloudera, Inc. licenses this file
  5. ## to you under the Apache License, Version 2.0 (the
  6. ## "License"); you may not use this file except in compliance
  7. ## with the License. You may obtain a copy of the License at
  8. ##
  9. ## http://www.apache.org/licenses/LICENSE-2.0
  10. ##
  11. ## Unless required by applicable law or agreed to in writing, software
  12. ## distributed under the License is distributed on an "AS IS" BASIS,
  13. ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ## See the License for the specific language governing permissions and
  15. ## limitations under the License.
  16. <%!
  17. from desktop.views import commonheader, commonfooter
  18. from django.utils.translation import ugettext as _
  19. from useradmin.password_policy import is_password_policy_enabled, get_password_hint
  20. from useradmin.views import is_user_locked_out
  21. %>
  22. <%namespace name="layout" file="layout.mako" />
  23. ${ commonheader(_('Hue Users'), "useradmin", user, request) | n,unicode }
  24. ${ layout.menubar(section='users') }
  25. <div class="container-fluid">
  26. <div class="card card-small">
  27. % if username:
  28. <h1 class="card-heading simple">${_('Hue Users - Edit user: %(username)s') % dict(username=username)}</h1>
  29. % else:
  30. <h1 class="card-heading simple">${_('Hue Users - Create user')}</h1>
  31. % endif
  32. <br/>
  33. <form id="editForm" method="POST" class="form form-horizontal" autocomplete="off">
  34. ${ csrf_token(request) | n,unicode }
  35. <div id="properties" class="section">
  36. <ul class="nav nav-tabs" style="margin-bottom: 0">
  37. <li class="active">
  38. <a href="#step1" class="step">${ _('Step 1: Credentials') }
  39. % if not username:
  40. ${ _('(required)') }
  41. % endif
  42. </a>
  43. </li>
  44. <li><a href="#step2" class="step">${ user.is_superuser and _('Step 2: Profile and Groups') or _('Step 2: Profile') }</a>
  45. </li>
  46. % if user.is_superuser:
  47. <li><a href="#step3" class="step">${ _('Step 3: Advanced') }</a></li>
  48. % endif
  49. </ul>
  50. <div class="steps">
  51. <div id="step1" class="stepDetails">
  52. ${layout.render_field(form["username"], extra_attrs={'validate':'true'})}
  53. % if "password1" in form.fields:
  54. % if username and "password_old" in form.fields:
  55. ${layout.render_field(form["password_old"], extra_attrs=username is None and {'validate':'true'} or {})}
  56. % endif
  57. ${layout.render_field(form["password1"], extra_attrs=username is None and {'validate':'true'} or {})}
  58. % if is_password_policy_enabled():
  59. <div class="password_rule" style="margin-left:180px; width:500px;">
  60. <p>${get_password_hint()}</p>
  61. </div>
  62. % endif
  63. ${layout.render_field(form["password2"], extra_attrs=username is None and {'validate':'true'} or {})}
  64. % endif
  65. ${layout.render_field(form["ensure_home_directory"])}
  66. </div>
  67. <div id="step2" class="stepDetails hide">
  68. % if "first_name" in form.fields:
  69. ${layout.render_field(form["first_name"])}
  70. ${layout.render_field(form["last_name"])}
  71. % endif
  72. ${layout.render_field(form["email"])}
  73. %if request.user.username == username:
  74. ${layout.render_field(form["language"])}
  75. % endif
  76. % if user.is_superuser:
  77. ${layout.render_field(form["groups"])}
  78. % endif
  79. </div>
  80. % if user.is_superuser:
  81. <div id="step3" class="stepDetails hide">
  82. ${layout.render_field(form["is_active"])}
  83. ${'is_superuser' in form.fields and layout.render_field(form["is_superuser"])}
  84. % if is_user_locked_out(username):
  85. ${layout.render_field(form["unlock_account"])}
  86. % endif
  87. </div>
  88. % endif
  89. </div>
  90. <div class="form-actions">
  91. <a id="backBtn" class="btn disabled">${ _('Back') }</a>
  92. <a id="nextBtn" class="btn btn-primary disable-feedback">${ _('Next') }</a>
  93. % if username:
  94. <input type="submit" class="btn btn-primary" value="${_('Update user')}"/>
  95. % else:
  96. <input type="submit" class="btn btn-primary" value="${_('Add user')}"/>
  97. % endif
  98. </div>
  99. </form>
  100. </div>
  101. </div>
  102. <script src="${ static('desktop/ext/js/routie-0.3.0.min.js') }" type="text/javascript" charset="utf-8"></script>
  103. <script type="text/javascript" charset="utf-8">
  104. $(document).ready(function(){
  105. $("#id_groups").jHueSelector({
  106. selectAllLabel: "${_('Select all')}",
  107. searchPlaceholder: "${_('Search')}",
  108. noChoicesFound: "${_('No groups found.')} <a href='${url('useradmin.views.edit_group')}'>${_('Create a new group now')} &raquo;</a>",
  109. width:618,
  110. height:240
  111. });
  112. var currentStep = "step1";
  113. routie({
  114. "step1":function () {
  115. showStep("step1");
  116. },
  117. "step2":function () {
  118. if (validateStep("step1")) {
  119. showStep("step2");
  120. }
  121. },
  122. "step3":function () {
  123. if (validateStep("step1") && validateStep("step2")) {
  124. showStep("step3");
  125. }
  126. }
  127. });
  128. function showStep(step) {
  129. currentStep = step;
  130. if (step != "step1") {
  131. $("#backBtn").removeClass("disabled");
  132. } else {
  133. $("#backBtn").addClass("disabled");
  134. }
  135. if (step != $(".stepDetails:last").attr("id")) {
  136. $("#nextBtn").removeClass("disabled");
  137. } else {
  138. $("#nextBtn").addClass("disabled");
  139. }
  140. $("a.step").parent().removeClass("active");
  141. $("a.step[href=#" + step + "]").parent().addClass("active");
  142. $(".stepDetails").hide();
  143. $("#" + step).show();
  144. }
  145. function validateStep(step) {
  146. var proceed = true;
  147. $("#" + step).find("[validate=true]").each(function () {
  148. if ($(this).val().trim() == "") {
  149. proceed = false;
  150. routie(step);
  151. $(this).parents(".control-group").addClass("error");
  152. $(this).parent().find(".help-inline").remove();
  153. $(this).after("<span class=\"help-inline\"><strong>${ _('This field is required.') }</strong></span>");
  154. }
  155. });
  156. return proceed;
  157. }
  158. $("#backBtn").click(function () {
  159. var nextStep = (currentStep.substr(4) * 1 - 1);
  160. if (nextStep >= 1) {
  161. routie("step" + nextStep);
  162. }
  163. });
  164. $("#nextBtn").click(function () {
  165. var nextStep = (currentStep.substr(4) * 1 + 1);
  166. if (nextStep <= $(".step").length) {
  167. routie("step" + nextStep);
  168. }
  169. });
  170. $("[validate=true]").change(function () {
  171. $(this).parents(".control-group").removeClass("error");
  172. $(this).parent().find(".help-inline").remove();
  173. });
  174. $("#editForm").on("submit", function(){
  175. if (validateStep("step1") && validateStep("step2")) {
  176. return true;
  177. }
  178. return false;
  179. })
  180. });
  181. </script>
  182. ${layout.commons()}
  183. ${ commonfooter(None, messages) | n,unicode }