strolch-wc-inspector/strolch-wc-role-privilege.html

269 lines
9.1 KiB
HTML

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-ajax/iron-ajax.html">
<link rel="import" href="../iron-pages/iron-pages.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="../paper-styles/color.html">
<link rel="import" href="../paper-material/paper-material.html">
<link rel="import" href="../paper-dialog/paper-dialog.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="../paper-item/paper-item.html">
<link rel="import" href="../paper-listbox/paper-listbox.html">
<link rel="import" href="../paper-tabs/paper-tabs.html">
<link rel="import" href="../strolch-wc-styles/strolch-wc-styles.html">
<link rel="import" href="strolch-wc-inspector-behavior.html">
<dom-module id="strolch-wc-role-privilege">
<template>
<style is="custom-style" include="strolch-wc-styles">
:host {
display: block;
margin: 0;
padding: 0;
}
paper-material {
background-color: white;
}
ul {
list-style: none;
}
.content {
border-top: 1px black solid;
}
</style>
<paper-material class="g-mt-0 g-mb-0 g-ml-4 g-mr-4" elevation="1">
<h3 class="g-pl-2 g-pt-1 g-pb-0" on-tap="_toggleOpened">
<template is="dom-if" if="[[!opened]]">
<paper-icon-button icon="arrow-drop-down"></paper-icon-button>
</template>
<template is="dom-if" if="[[opened]]">
<paper-icon-button icon="arrow-drop-up"></paper-icon-button>
</template>
[[privilege.name]]
<paper-icon-button on-tap="_removePrivilege" class="g-pull-right" icon="delete"></paper-icon-button>
</h3>
<template is="dom-if" if="[[opened]]">
<div class="content g-pt-0 g-pb-2 g-pl-4 g-pr-4">
<paper-input class="g-mt-2"
label="Policy"
on-input="_inputChanged"
value="{{privilege.policy}}"></paper-input>
<paper-checkbox class="g-mt-3" on-tap="_inputChanged" checked="{{privilege.allAllowed}}">All allowed
</paper-checkbox>
<template is="dom-if" if="[[!privilege.allAllowed]]">
<br />
<template is="dom-if" if="[[!hasAllows]]">
<p>Allow List: <i>none</i></p>
</template>
<template is="dom-if" if="[[hasAllows]]">
<p>Allow List:</p>
<ul>
<template is="dom-repeat" items="[[privilege.allowList]]">
<li>
<paper-icon-button icon="remove-circle-outline"
title="Remove"
on-tap="_removeAllowValue"></paper-icon-button>
[[item]]
</li>
</template>
</ul>
</template>
<template is="dom-if" if="[[!hasDenies]]">
<p>Deny List: <i>none</i></p>
</template>
<template is="dom-if" if="[[hasDenies]]">
<p>Deny List:</p>
<ul>
<template is="dom-repeat" items="[[privilege.denyList]]">
<li>
<paper-icon-button icon="remove-circle-outline"
title="Remove"
on-tap="_removeDenyValue"></paper-icon-button>
[[item]]
</li>
</template>
</ul>
</template>
<paper-button on-tap="_addAllowValue">Add Allow</paper-button>
<paper-button on-tap="_addDenyValue">Add Deny</paper-button>
</template>
</div>
</template>
</paper-material>
<paper-dialog id="dlg" modal>
<h2>[[dlgTitle]]</h2>
<paper-input label="value" value="{{listValue}}"></paper-input>
<div class="buttons">
<paper-button dialog-confirm autofocus>Close</paper-button>
<paper-button on-tap="_saveAllowDenyValue">Add</paper-button>
</div>
</paper-dialog>
<iron-ajax id="ajax"
content-type="application/json"
handle-as="json"
on-response="_handleAjaxResponse"
on-error="onAjaxError"></iron-ajax>
</template>
<script>
Polymer({
is: 'strolch-wc-role-privilege',
behaviors: [
StrolchInspectorBehavior
],
properties: {
opened: {
type: Boolean,
value: false
},
role: {
type: Object
},
privilege: {
type: Object
},
hasAllows: {
type: Boolean,
computed: 'isNotEmptyArray(privilege.allowList)'
},
hasDenies: {
type: Boolean,
computed: 'isNotEmptyArray(privilege.denyList)'
},
listToAddTo: {
type: String
},
listValue: {
type: String
}
},
ready: function () {
//
},
reload: function () {
},
_handleAjaxResponse: function (evt) {
console.log('NOT YET DEFINED!');
},
_toggleOpened: function (e) {
this.opened = !this.opened;
},
_inputChanged: function (e) {
this.fire('strolch-changed', {});
},
_addAllowValue: function (e) {
this.dlgTitle = "Add Allow Value";
this.listToAddTo = 'allowList';
this.$.dlg.open();
},
_addDenyValue: function (e) {
this.dlgTitle = "Add Deny Value";
this.listToAddTo = 'denyList';
this.$.dlg.open();
},
_saveAllowDenyValue: function (e) {
if (this.isEmptyString(this.listValue)) {
return;
}
var path = 'privilege.' + this.listToAddTo;
this.push(path, this.listValue);
this.notifyPath(path);
this.fire('strolch-changed', {});
this.listToAddTo = '';
this.listValue = '';
this.$.dlg.close();
},
_removeAllowValue: function (e) {
var value = e.model.item;
var list = this.privilege.allowList;
var path = 'privilege.allowList';
this._removeValue(value, list, path);
},
_removeDenyValue: function (e) {
var value = e.model.item;
var list = this.privilege.denyList;
var path = 'privilege.denyList';
this._removeValue(value, list, path);
},
_removeValue: function (value, list, path) {
console.log('Removing value ' + value + ' for path ' + path);
for (var i = 0; i < list.length; i++) {
if (list[i] === value) {
list.splice(i, 1);
this.notifySplices(path, [
{
index: i,
removed: [value],
addedCount: 0,
obect: list,
type: 'splice'
}
]);
this.notifyPath(path);
this.fire('strolch-changed', {});
}
}
},
_removePrivilege: function (e) {
e.stopPropagation();
this.fire('strolch-remove-privilege', {privilege: this.privilege})
}
});
</script>
</dom-module>