{{!
  Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.

  WSO2 Inc. licenses this file to you under the Apache License,
  Version 2.0 (the "License"); you may not use this file except
  in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied. See the License for the
  specific language governing permissions and limitations
  under the License.
}}
{{unit "cdmf.unit.ui.title" pageTitle="User Management | Edit User"}}

{{#zone "breadcrumbs"}}
    <li>
        <a href="{{@app.context}}/">
            <i class="icon fw fw-home"></i>
        </a>
    </li>
    <li>
        <a href="{{@app.context}}/users">
            Users
        </a>
    </li>
    <li>
        <a href="#">
            Edit
        </a>
    </li>
{{/zone}}

{{#zone "content"}}
    {{#if canManage}}
        <!-- content/body -->
        <div class="row">
            <div class="col-md-12">
                <!-- content -->
                <div id="user-create-form" class="container col-centered wr-content">
                    <div class="wr-form">
                        <p class="page-sub-title">Edit User</p>
                        <p>Please note that * sign represents required fields of data.</p>
                        <hr/>
                        <div class="row">
                            <div class="col-lg-8">
                                <div id="user-create-error-msg" class="alert alert-danger hidden" role="alert">
                                    <i class="icon fw fw-error"></i><span></span>
                                </div>
                                <label class="wr-input-label"
                                       title="Select the domain of the user store from the drop-down given below. The domain of the default user store is PRIMARY">
                                    User Store Domain
                                    <span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
                                </label>
                                <div class="wr-input-control">
                                    <select id="userStore" class="form-control select" disabled>
                                        <option value="{{userStore}}" selected>{{userStore}}</option>
                                    </select>
                                </div>
                                <label class="wr-input-label">
                                    User Name <br>
                                </label>
                                <div class="wr-input-control">
                                    <input type="text" id="username" data-regex="{{usernameJSRegEx}}"
                                           data-errormsg="{{usernameRegExViolationErrorMsg}}" class="form-control"
                                           value="{{editUser.username}}" disabled/>
                                </div>
                                <label class="wr-input-label">First Name *</label>
                                <div id="firstNameField" class="form-group wr-input-control">
                                    <input type="text" id="firstname" data-regex="{{firstnameJSRegEx}}"
                                           data-errormsg="{{firstnameRegExViolationErrorMsg}}" class="form-control"
                                           value="{{editUser.firstname}}"/>
                                    <span class="glyphicon glyphicon-remove form-control-feedback hidden fnError"></span>
                                    <label class=" hidden error fnError" for="summary">This field is required.</label>
                                </div>
                                <label class="wr-input-label">Last Name *</label>
                                <div id="lastNameField" class="form-group wr-input-control">
                                    <input type="text" id="lastname" data-regex="{{lastnameJSRegEx}}"
                                           data-errormsg="{{lastnameRegExViolationErrorMsg}}" class="form-control"
                                           value="{{editUser.lastname}}"/>
                                    <span class="glyphicon glyphicon-remove form-control-feedback hidden lnError"></span>
                                    <label class=" hidden error lnError" for="summary">This field is required.</label>
                                </div>
                                <label class="wr-input-label">
                                    Email Address * <br>
                                    ( ex: sam@gmail.com )
                                </label>
                                <div id="emailField" class=" form-group wr-input-control">
                                    <input type="email" id="emailAddress" class="form-control"
                                           value="{{editUser.emailAddress}}"/>
                                    <span class="glyphicon glyphicon-remove form-control-feedback hidden emailError"></span>
                                    <label class=" hidden error email-required" for="summary">This field is
                                        required.</label>
                                    <label class=" hidden error email-invalid" for="summary">Invalid Email
                                        Address.</label>
                                </div>
                                {{#if canViewRoles}}
                                    <label class="wr-input-label"
                                           title="Optional field that can have 0-to-many roles for the user">
                                        User Roles
                                        <span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
                                    </label>
                                    <div class="wr-input-control">
                                        <select id="roles" class="form-control select2" multiple="multiple"
                                                selectedVals="{{#each rolesByUsername}} {{this}}, {{/each}}">
                                            {{#each rolesByUserStore}}
                                                <option>{{this}}</option>
                                            {{/each}}
                                        </select>
                                    </div>
                                {{/if}}
                            </div>
                        </div>
                        <br>
                        <button id="add-user-btn" class="wr-btn">Save User</button>
                    </div>
                </div>
                <div id="user-created-msg" class="container col-centered wr-content hidden">
                    <div class="wr-form">
                        <p class="page-sub-title">User was updated successfully.</p>

                        <br>Please click <b>"View Updated User"</b>, if you wish to view the updated user or click
                        <b>"View User List"</b> to complete the process and go back to the user list.
                        <hr/>
                        <button class="wr-btn" onclick="window.location.href='{{@app.context}}/users'">View User List
                        </button>
                        <a href="{{@app.context}}/user/view?username={{editUser.username}}" class="cu-btn-inner">
                        <span class="fw-stack">
                            <i class="fw fw-circle-outline fw-stack-2x"></i>
                            <i class="fw fw-view fw-stack-1x"></i>
                        </span>
                            View Updated User
                        </a>
                    </div>
                </div>
                <!-- /content -->
            </div>
        </div>
        <!-- /content/body -->
    {{else}}
        <h1 class="page-sub-title">
            Permission Denied
        </h1>
        <br>
        You not authorized to enter User Management Section.
        <br>
    {{/if}}

{{/zone}}

{{#zone "bottomJs"}}
    {{js "js/bottomJs.js"}}
{{/zone}}
