{{!
  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="Role Management"}}

{{#zone "breadcrumbs"}}
    <li>
        <a href="{{@app.context}}/">
            <i class="icon fw fw-home"></i>
        </a>
    </li>
    <li>
        <!--suppress HtmlUnknownTarget -->
        <a href="{{@app.context}}/roles">
            Roles
        </a>
    </li>
    <li>
        <!--suppress HtmlUnknownTarget -->
        <a href="{{@app.context}}/role/add">
            Add
        </a>
    </li>
{{/zone}}

{{#zone "content"}}
    {{#if canManage}}
        <!-- content/body -->
        <div class="row">
            <div class="col-md-12">
                <!-- content -->
                <div id="role-create-form" data-cloud={{isCloud}} class="container col-centered wr-content
                ">
                <div class="wr-form">
                    <p class="page-sub-title">Add Role</p>
                    <hr/>
                    <div class="row">
                        <div class="col-lg-8">
                            <div class="wr-steps">
                                <div class="col-md-6 col-xs-6">
                                    <div class="itm-wiz itm-wiz-current" data-step="policy-platform">
                                        <div class="wiz-no">1</div>
                                        <div class="wiz-lbl hidden-xs"><span>Add a role</span></div>
                                    </div>
                                </div>
                                <div class="col-md-6 col-xs-6">
                                    <div class="itm-wiz" data-step="policy-profile">
                                        <div class="wiz-no">2</div>
                                        <div class="wiz-lbl hidden-xs"><span>Assign permissions</span></div>
                                    </div>
                                </div>
                                <br class="c-both"/>
                            </div>
                            <br/><br/>
                            <hr/>
                            <div id="role-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">User Store Domain</label>
                            <div class="wr-input-control">
                                <!--suppress HtmlFormInputWithoutLabel -->
                                <select id="domain" class="form-control select">
                                    <option>PRIMARY</option>
                                    {{#each userStores}}
                                        <option>{{this}}</option>
                                    {{/each}}
                                </select>
                            </div>

                            <label class="wr-input-label">
                                Role Name *
                            </label>
                            <br>
                            <label class="wr-input-label">
                                ( {{roleNameHelpText}} )
                            </label>
                            {{#if isCloud}}
                            <div id="roleNameField" class="form-group wr-input-control input-group">
                                <!--suppress HtmlFormInputWithoutLabel -->
                                <span class="input-group-addon" id="basic-addon1">devicemgt</span>
                                <input aria-describedby="basic-addon1" type="text" id="roleName"
                                       data-regex="{{roleNameJSRegEx}}"
                                       data-error-msg="{{roleNameRegExViolationErrorMsg}}" class="form-control"/>
                            {{else}}
                            <div id="roleNameField" class="form-group wr-input-control">
                                <!--suppress HtmlFormInputWithoutLabel -->
                                <input type="text" id="roleName" data-regex="{{roleNameJSRegEx}}"
                                       data-error-msg="{{roleNameRegExViolationErrorMsg}}" class="form-control"/>
                            {{/if}}
                            <span class="roleNameError hidden glyphicon glyphicon-remove form-control-feedback"></span>
                            <label class="error roleNameEmpty hidden" for="summary">
                                Role name is required, should be in minimum 3 characters long and not include any
                                whitespaces or "@" character or "/" character.
                            </label>
                        </div>
                            {{#if canViewUsers}}
                                <label class="wr-input-label">
                                    User list
                                </label>

                                <div class="wr-input-control">
                                    <!--suppress HtmlFormInputWithoutLabel -->
                                    <select id="users" class="form-control select2" multiple="multiple"></select>
                                </div>
                            {{/if}}
                        </div>
                        </div>
                        <br>
                        <button id="add-role-btn" class="wr-btn">Add Role</button>
                    </div>
                </div>
                <div id="role-created-msg" class="container col-centered wr-content hidden">
                    <div class="wr-form">
                        <p class="page-sub-title">Role was added successfully.</p>
                        <br>Please click <b>"Add Another Role"</b>, if you wish to add another role or click
                        <b>"View Role List"</b> to complete the process and go back to the role list.
                        <hr/>
                        <button class="wr-btn" onclick="window.location.href='{{@app.context}}/roles'">
                            View Role List
                        </button>
                        <!--suppress HtmlUnknownTarget -->
                        <a href="{{@app.context}}/role/add" class="cu-btn-inner">
                        <span class="fw-stack">
                            <i class="fw fw-circle-outline fw-stack-2x"></i>
                            <i class="fw fw-add fw-stack-1x"></i>
                        </span>
                            Add Another Role
                        </a>
                    </div>
                </div>
                <!-- /content -->
                <div id="app-context" data-app-context="{{@app.context}}" class="hidden"></div>
            </div>
        </div>
        <!-- /content/body -->
    {{else}}
        <h1 class="page-sub-title">
            Permission Denied
        </h1>
        <br>
        You not authorized to enter Role Management Section.
        <br>
    {{/if}}
{{/zone}}
{{#zone "bottomJs"}}
    {{js "js/bottomJs.js"}}
{{/zone}}