2018-03-19 22:29:46 +01:00
|
|
|
<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>
|
|
|
|
|
2018-09-07 15:31:51 +02:00
|
|
|
<style is="custom-style" include="strolch-wc-styles">
|
2018-03-19 22:29:46 +01:00
|
|
|
|
|
|
|
:host {
|
|
|
|
display: block;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
paper-material {
|
|
|
|
background-color: white;
|
|
|
|
}
|
|
|
|
|
|
|
|
ul {
|
|
|
|
list-style: none;
|
|
|
|
}
|
|
|
|
|
2018-03-20 12:07:58 +01:00
|
|
|
.content {
|
|
|
|
border-top: 1px black solid;
|
|
|
|
}
|
|
|
|
|
2018-03-19 22:29:46 +01:00
|
|
|
</style>
|
|
|
|
|
2018-03-20 12:07:58 +01:00
|
|
|
<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">
|
2018-03-19 22:29:46 +01:00
|
|
|
<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]]
|
2018-03-20 12:07:58 +01:00
|
|
|
<paper-icon-button on-tap="_removePrivilege" class="g-pull-right" icon="delete"></paper-icon-button>
|
2018-03-19 22:29:46 +01:00
|
|
|
</h3>
|
|
|
|
|
|
|
|
<template is="dom-if" if="[[opened]]">
|
|
|
|
|
2018-03-20 12:07:58 +01:00
|
|
|
<div class="content g-pt-0 g-pb-2 g-pl-4 g-pr-4">
|
2018-03-19 22:29:46 +01:00
|
|
|
|
2018-03-20 12:07:58 +01:00
|
|
|
<paper-input class="g-mt-2"
|
|
|
|
label="Policy"
|
|
|
|
on-input="_inputChanged"
|
|
|
|
value="{{privilege.policy}}"></paper-input>
|
2018-03-19 22:29:46 +01:00
|
|
|
|
2018-03-20 12:07:58 +01:00
|
|
|
<paper-checkbox class="g-mt-3" on-tap="_inputChanged" checked="{{privilege.allAllowed}}">All allowed
|
|
|
|
</paper-checkbox>
|
2018-03-19 22:29:46 +01:00
|
|
|
|
|
|
|
<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>
|
2018-03-20 12:07:58 +01:00
|
|
|
<paper-icon-button icon="remove-circle-outline"
|
2018-03-19 22:29:46 +01:00
|
|
|
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>
|
2018-03-20 12:07:58 +01:00
|
|
|
<paper-icon-button icon="remove-circle-outline"
|
2018-03-19 22:29:46 +01:00
|
|
|
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>
|
|
|
|
|
2018-03-20 12:07:58 +01:00
|
|
|
<paper-input label="value" value="{{listValue}}"></paper-input>
|
2018-03-19 22:29:46 +01:00
|
|
|
|
|
|
|
<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;
|
|
|
|
},
|
|
|
|
|
2018-03-20 12:07:58 +01:00
|
|
|
_inputChanged: function (e) {
|
|
|
|
this.fire('strolch-changed', {});
|
|
|
|
},
|
|
|
|
|
2018-03-19 22:29:46 +01:00
|
|
|
_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) {
|
2018-03-20 12:07:58 +01:00
|
|
|
if (this.isEmptyString(this.listValue)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-19 22:29:46 +01:00
|
|
|
var path = 'privilege.' + this.listToAddTo;
|
|
|
|
this.push(path, this.listValue);
|
|
|
|
this.notifyPath(path);
|
2018-03-20 12:07:58 +01:00
|
|
|
this.fire('strolch-changed', {});
|
2018-03-19 22:29:46 +01:00
|
|
|
|
|
|
|
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) {
|
|
|
|
|
2018-03-20 12:07:58 +01:00
|
|
|
console.log('Removing value ' + value + ' for path ' + path);
|
2018-03-19 22:29:46 +01:00
|
|
|
|
|
|
|
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);
|
2018-03-20 12:07:58 +01:00
|
|
|
this.fire('strolch-changed', {});
|
2018-03-19 22:29:46 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-20 12:07:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
_removePrivilege: function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.fire('strolch-remove-privilege', {privilege: this.privilege})
|
2018-03-19 22:29:46 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</dom-module>
|