<block id="admin_breadcrumb">
	<li class="breadcrumb-item"><a href="../panels/helpdesk_admin.php"><txt name="panels:general:helpdesk">Helpdesk control panel</txt></a></li>
    <li class="breadcrumb-item"><a name="project_properties_link" href="../infocapture/admin_summary_project.php?id={project_id}"><txt name="project_name">Project Name</txt></a></li>
	<li class="breadcrumb-item active" aria-current="page"><txt name="helpdesk:project:edit_fields_rights">Edit rights for issues fields</txt></li>
</block>

<block id="page_body">
	<component class_key="js_localize" keys="infocapture.admin.field_rights.permission_default,
    infocapture.admin.field_rights.permission_allow,
    infocapture.admin.field_rights.permission_deny,
    infocapture.admin.field_rights.right_view,
    infocapture.admin.field_rights.right_edit,
    infocapture.admin.general.unsaved_changes,
    infocapture.admin.general.changes_saved,
    infocapture.admin.field_rights.filter_input">
<txt name="xajax"></txt>

<script type="text/javascript">
	require(['infocapture/field_rights', 'domReady'], function (ICFieldRights, domReady) {
        window.groups = ${groups_data.json};
        window.group_inactives = ${groups_data.json};
        /*{ bitmask:-1, name:"All", position:0 }*/
        window.roles =  ${roles_data.json};
        window.rules = ${rules_data.json};
        window.projectId = ${project_id};
		domReady(function () {
            ICFieldRights.init();
		});
	});
</script>

<h4 name="helpdesk:project:edit_fields_rights">Field Visibility</h4>
<p class="text-muted"><loc name="infocapture:edit_fields_rights:introduction">Field visibility allows you to define whether your form’s fields should show or hide.</loc>
<component name="help_text" class_key="infocapture.help_text" lmsg="infocapture.edit_fields_rights.help_text" key="helpdesk_edit_fields_rights" />
</p>

<div class="card field-group-actions mb-3" data-spy="affix" data-offset-top="200">
	<div class="card-body">
		<div class="row">
			<div class="col-md-6">
				<form action="" method="post" id="filter-form">
					<div class="row">
						<div class="col-md-8">
				        	<input type="text" name="infocapture:admin:field_rights:filter_input" id="filterGroups" class="form-control" placeholder="Filter.." />
				    	</div>
					    <div class="col-md-4">
				        	<input id="resetFilterGroups" name="infocapture:admin:field_rights:filter_clear" type="button" value="Clear" class="btn btn-secondary" />
			        	</div>
					</div>
			    </form>
			</div>
			<div class="col-md-6">
				<div class="btn-group float-right" role="group" aria-label="field rights group">
					<a href="#" id="undo" class="btn btn-secondary" style="display: none;">
					<ion-icon name="arrow-undo-outline"></ion-icon> <loc name="infocapture:admin:undo">Undo</loc>
					</a>

					<a href="#" id="save" class="btn btn-primary" style="display: none;" data-project-id="${project_id}">
						<ion-icon name="checkbox-outline"></ion-icon> <loc name="infocapture:admin:save">Save</loc>
					</a>

					<a href="#" id="saving" class="btn btn-primary" style="display: none;">
						<ion-icon name="refresh-circle-outline"></ion-icon> <loc name="infocapture:admin:saving">Saving</loc>
					</a>
					<a href="admin_edit_field_groups.php?id=${project_id}" name="infocapture:admin:manage_groups" class="btn btn-secondary">Manage Groups</a>
				</div>
			</div>
		</div>
    </div>
</div>

<form name="fields_rights_form" method="post" action="">
    <div id="group-list"></div>
    <input type="hidden" name="csrf_token" value="" />
    <input type="hidden" name="rule_number" value="" />
    <input type="hidden" name="group_number" value="" />
</form>

<div class="modal fade" id="add-rule-modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title"><loc>Add rule</loc></h5>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">
						<ion-icon name="close-outline"></ion-icon>
					</span>
				</button>
			</div>
			<div class="modal-body">
		        <div class="alert alert-danger" id="field_condition_sets_empty_error"><txt name="helpdesk:project:error_field_conditions_set_empty"></txt></div>

				<div class="form-group row">
					<label for="add_rule_id" class="col-form-label col-md-3 col-sm-2"><txt name="helpdesk:project:fields_conditions_set">Field condition set</txt></label>

		            <div class="col-md-9 col-sm-10">
	                    <select name="add_rule_id" id="add-rule-id" class="form-control select2-max-width" data-apply="select2"></select>
		            </div>
		        </div>
			</div>
			<div class="modal-footer">
		        <button type="button" class="btn btn-secondary" data-dismiss="modal" aria-label="Close"><loc name="common:cancel">Cancel</loc></button>

				<a class="btn btn-info" target="_blank" href="/intranet/panels/helpdesk_edit_rules.php?id=${project_id_val.value}&amp;action=edit_rule&amp;for_fields_rights=1"><loc name="helpdesk:project:add_new_conditions_set">Add new condition set</loc> <span class="glyphicons glyphicons-new-window-alt"></span></a>

				<a href="#" class="btn btn-success" id="add-rule"><loc name="infocapture:admin:field_rights:add_rule">Add</loc></a>
			</div>
		</div>
	</div>
</div>

<div class="modal fade" id="edit-rule-modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title"><loc>Edit rule</loc></h5>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">
						<ion-icon name="close-outline"></ion-icon>
					</span>
				</button>
			</div>
			<div class="modal-body">
				<div class="form-group row">
					<label for="edit_rule_id" class="col-form-label col-md-3 col-sm-2"><txt name="helpdesk:project:fields_conditions_set">Field condition set</txt></label>

		            <div class="col-md-9 col-sm-10">
		                <p>
		                    <select name="edit_rule_id" id="edit-rule-id" class="form-control select2-max-width" data-apply="select2"></select>
		                </p>
					     <p>
		                    <a class="btn btn-secondary" name="helpdesk:project:add_new_conditions_set" target="_blank" href="/intranet/panels/helpdesk_edit_rules.php?id=${project_id_val.value}&amp;action=edit_rule&amp;for_fields_rights=1">
		                        Add new condition set</a>
		                </p>
		            </div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-secondary" data-dismiss="modal"><loc name="common:cancel">Cancel</loc></button>

				<a href="#" class="btn btn-primary" id="edit-rule" name="infocapture:admin:field_rights:submit">aSubmit</a>
			</div>
		</div>
	</div>
</div>

<script type="text/template" id="group-tmpl">
	<div class="field-permissions" name="groups" data-group-id="{{=id}}" id="group-{{= id }}">
    	<a class="accordion-toggle" data-toggle="collapse" href="#collapse-{{= id }}">
        	<span class="icon-only glyphicons">
        		<span class="glyphicons-collapse glyphicons"></span>
        	</span>
        	{{- name }}
        </a>

        <div id="collapse-{{= id }}" class="collapse">
            <div class="field-options form-inline">
                <div class="field-list"></div>

               	{{ if(dropdown.length > 0) { }}

									<div class="form-group row copy-perm-block">
										<label for="groupName" class="col-form-label col-md-2 col-sm-2"><txt name="helpdesk:project:copy_group_rights">Copy rights from group</txt></label>
										<select name="groupName" class="form-control mr-2">
												<option value="" name="infocapture:admin:field_rights:copy_select_group">Select a group...</option>
												{{ _.each(dropdown, function(data){ }}
													<option value="{{=data.id}}">{{- data.name }}</option>
												{{ }); }}
										</select>
										<button class="btn btn-secondary" name="copy_perms_btn" data-group-id="{{- id }}" ><loc name="infocapture:admin:field_rights:copy">Copy</loc></button>
									</div>

                {{ } }}
            </div>
        </div>
        <div class="table-responsive">
            <table cellspacing="0" cellpadding="0" width="100%" class="table table-striped field-rights-group">
                <tbody class="sortable rights-list">

                </tbody>
				<tfoot>
				<tr>
					<td colspan="8" name="td_buttons">
						<a class="btn btn-success" name="new_rule_link" href="#group-{{= id }}" data-group-id="{{= id }}">
							<ion-icon name="add-outline"></ion-icon> <loc name="infocapture:admin:field_rights:add_condition_set">Add Condition Set</loc>
						</a>
					</td>
				</tr>
				</tfoot>
            </table>
        </div>
    </div>
</script>

<script type="text/template" id="rights-tmpl">
	<tr data-rule-id="{{- ruleId }}" data-group-id="{{- groupId }}">
		<td class="text-nowrap">
			<a href="javascript:void(0)"><span class="glyphicons-drag glyphicons js-drag-handle"></span></a>
        	<a href="javascript:void(0)" data-rule-id="{{- ruleId }}" data-group-id="{{- groupId }}" name="edit_rule">{{- name }}</a>
        </td>

        <td class="text-center">
            <a href="#group-{{= groupId }}" name="del_link" rel="tooltip" title="${common:delete.body}" data-group-id="{{- groupId }}" data-rule-id="{{- ruleId }}">
            	<ion-icon name="trash-outline"></ion-icon>
            </a>
        </td>
	</tr>
</script>

<script type="text/template" id="right-tmpl">
	<td class="text-center" data-bitmask="{{- bitmask }}" data-mode="{{- mode }}">
		{{ if(right === 0) { }}
	    	<a href="#" data-mode="{{- mode }}" data-value="0" data-bitmask="{{- bitmask }}" class="badge badge-pill badge-secondary">
	    		<loc name="infocapture:admin:field_rights:permission_default">Default</loc>
	    	</a>
	    {{ } }}
	    {{ if(right === 1) { }}
	    	<a href="#" data-mode="{{- mode }}" data-value="1" data-bitmask="{{- bitmask }}" class="badge badge-pill badge-success">
	    		<loc name="infocapture:admin:field_rights:permission_allow">Allow</loc>
	    	</a>
	    {{ } }}
	    {{ if(right === 2) { }}
	    	<a href="#" data-mode="{{- mode }}" data-value="2" data-bitmask="{{- bitmask }}" class="badge badge-pill badge-danger">
	    		<loc name="infocapture:admin:field_rights:permission_deny">Deny</loc>
	    	</a>
	    {{ } }}
		{{ if(right === 3) { }}
		<a href="#" data-mode="{{- mode }}" data-value="3" data-bitmask="{{- bitmask }}" class="badge badge-pill badge-info">
			<loc name="infocapture:admin:field_rights:permission_mixed">_Mixed</loc>
		</a>
		{{ } }}
	</td>
</script>

<script type="text/template" id="roles-tmpl">
	<colgroup class="role-col-group">
	    <col />
	</colgroup>
	<thead>
	    <tr class="role-header">
	        <th>&nbsp;</th>
	        <th>&nbsp;</th>
	    </tr>
	    <tr class="subheader role-subheader">
	        <th><txt name="helpdesk:project:fields_conditions_set">Fields conditions set</txt></th>
	        <th>&nbsp;</th>
	    </tr>
	</thead>
</script>

<script type="text/template" id="fields-tmpl">
	{{= active_fields}}
  <div class="col-md-12">
    <p>
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordionGroup1" href="#collapse-inactive-{{= group_id}}" style="{{inactive_fields.length>0 ? '':print('display:none');}}">
        <span class="icon-only glyphicons">
          <span class="glyphicons-collapse glyphicons"></span>
        </span>
        <loc name="infocapture:admin:inactive_fields">[Inactive Fields]</loc>
      </a>
    </p>

    <div id="collapse-inactive-{{= group_id}}" class="collapse">
      <div class="inactive-field-list row">
        {{= inactive_fields}}
      </div>
    </div>
  </div>
</script>

<script type="text/template" id="fields-column-tmpl">
	<div class="col-md-3">
		{{= fieldList }}
	</div>
</script>

<script type="text/template" id="rule-tmpl">
	<option name="rule" value="{{- ruleId }}">{{- name }}</option>
</script>

<script type="text/template" id="right-select-tmpl">
	<div class="field-list-options">
		<ul id="state-select" class="list-unstyled">
			{{ _.each(states, function(state) { }}
				<li><a href="#" class="{{-state.badgeName}}" data-right="{{- state.right }}">
				{{ if(state.current === true) { }}<span class="glyphicons-ok glyphicons"></span>{{ } else { }} <span class="icon-xstar glyphicons"></span> {{ } }}
				{{- state.name }}</a></li>
			{{ }); }}
		</ul>
	</div>
</script>

</block>

<include file="../layouts/admin_with_project.html">
