Commit 9e820b49 authored by Wolfgang's avatar Wolfgang

Fix pb-select-feature init in same way as pb-toggle-feature

parent 8c5715d7
......@@ -50,7 +50,7 @@
</pb-select-feature>
</div>
<main>
<pb-view id="view1" src="document1" view="single" xpath="//text[@type='source']"></pb-view>
<pb-view id="view1" src="document1" view="single"></pb-view>
</main>
</template>
</demo-snippet>
......
......@@ -67,12 +67,27 @@
type: String,
observer: '_changed'
},
/**
* If set to true (default), `pb-toggle-feature` will pass its properties to the
* connected view before this loads content for the first time. If false,
* `pb-toggle-feature` will initialize its state depending on the setting of the view.
* This only makes sense for the special properties 'view' and 'odd' though.
*/
initFromView: {
type: Boolean,
value: false
},
_items: {
type: Array
}
};
}
constructor() {
super();
this.initializing = true;
}
connectedCallback() {
super.connectedCallback();
......@@ -89,40 +104,58 @@
});
}.bind(this));
let param = this.getParameter(this.name);
if (typeof param !== 'undefined') {
this.selected = param;
if (this.initFromView) {
this.subscribeTo('pb-update', this._initialize.bind(this));
} else {
this.selected = this._items[0].value;
let param = this.getParameter(this.name);
if (typeof param !== 'undefined') {
this.selected = param;
} else {
this.selected = this._items[0].value;
}
this.waitForChannel(() => {
const props = {};
props[this.name] = this.selected;
const params = {
properties: props,
action: 'init'
};
this.emitTo('pb-toggle', params);
this.initializing = false;
});
}
this.waitForChannel(() => {
const props = {};
props[this.name] = this.selected;
const params = {
properties: props,
action: 'init'
};
this.emitTo('pb-toggle', params);
});
this.signalReady();
}
_changed(newVal, oldVal) {
if (typeof oldVal !== 'undefined' && newVal !== oldVal) {
if (!this.name) {
return;
}
this.setParameter(this.name, this.selected);
this.pushHistory('toggle feature ' + this.name);
_initialize(ev) {
if (!this.initializing) {
return;
}
switch (this.name) {
case 'view':
this.selected = ev.detail.data.view;
break;
case 'odd':
this.selected = ev.detail.data.odd;
break;
}
this.initializing = false;
}
const props = {};
props[this.name] = this.selected;
const params = {
action: 'refresh',
properties: props
};
this.emitTo('pb-toggle', params);
_changed(newVal, oldVal) {
if (this.initializing || !this.name) {
return;
}
this.setParameter(this.name, this.selected);
this.pushHistory('toggle feature ' + this.name);
const props = {};
props[this.name] = this.selected;
const params = {
action: 'refresh',
properties: props
};
this.emitTo('pb-toggle', params);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment