fchat-rising/chat/ConversationSettings.vue

143 lines
5.7 KiB
Vue
Raw Normal View History

2017-09-02 01:50:31 +00:00
<template>
2019-01-03 17:38:17 +00:00
<modal :action="l('conversationSettings.action', conversation.name)" @submit="submit" ref="dialog" @open="load()" dialogClass="w-100"
2018-07-20 01:12:26 +00:00
:buttonText="l('conversationSettings.save')">
2017-09-02 01:50:31 +00:00
<div class="form-group">
<label class="control-label" :for="'notify' + conversation.key">{{l('conversationSettings.notify')}}</label>
<select class="form-control" :id="'notify' + conversation.key" v-model="notify">
<option :value="setting.Default">{{l('conversationSettings.default')}}</option>
<option :value="setting.True">{{l('conversationSettings.true')}}</option>
<option :value="setting.False">{{l('conversationSettings.false')}}</option>
</select>
</div>
<div class="form-group">
<label class="control-label" :for="'highlight' + conversation.key">{{l('settings.highlight')}}</label>
<select class="form-control" :id="'highlight' + conversation.key" v-model="highlight">
<option :value="setting.Default">{{l('conversationSettings.default')}}</option>
<option :value="setting.True">{{l('conversationSettings.true')}}</option>
<option :value="setting.False">{{l('conversationSettings.false')}}</option>
</select>
</div>
2017-10-18 23:29:28 +00:00
<div class="form-group">
<label class="control-label" for="defaultHighlights">
<input type="checkbox" id="defaultHighlights" v-model="defaultHighlights"/>
{{l('settings.defaultHighlights')}}
</label>
</div>
2017-09-02 01:50:31 +00:00
<div class="form-group">
<label class="control-label" :for="'highlightWords' + conversation.key">{{l('settings.highlightWords')}}</label>
2017-10-18 23:29:28 +00:00
<input :id="'highlightWords' + conversation.key" class="form-control" v-model="highlightWords"/>
2017-09-02 01:50:31 +00:00
</div>
<div class="form-group">
<label class="control-label" :for="'joinMessages' + conversation.key">{{l('settings.joinMessages')}}</label>
<select class="form-control" :id="'joinMessages' + conversation.key" v-model="joinMessages">
<option :value="setting.Default">{{l('conversationSettings.default')}}</option>
<option :value="setting.True">{{l('conversationSettings.true')}}</option>
<option :value="setting.False">{{l('conversationSettings.false')}}</option>
</select>
</div>
<h5>Auto-Posting Channel Ads</h5>
<div class="form-group ad-list" v-for="(ad, index) in ads">
<label :for="'ad' + conversation.key + '-' + index" class="control-label">Ad #{{(index + 1)}}
<a v-if="(index > 0)" @click="moveAdUp(index)" title="Move Up"><i class="fa fa-arrow-up"></i></a>
<a v-if="(index < ads.length - 1)" @click="moveAdDown(index)" title="Move Down"><i class="fa fa-arrow-down"></i></a>
<a @click="removeAd(index)" title="Remove Ad"><i class="fa fa-minus-circle"></i></a>
</label>
2019-06-03 00:42:05 +00:00
<textarea :id="'ad' + conversation.key + '-' + index" class="form-control" v-model="ads[index]"></textarea>
2019-06-02 23:57:32 +00:00
</div>
<button class="btn btn-outline-secondary" @click="addAd()">Add Another</button>
2019-06-02 23:57:32 +00:00
2017-09-02 01:50:31 +00:00
</modal>
</template>
<script lang="ts">
2019-01-03 17:38:17 +00:00
import {Component, Prop} from '@f-list/vue-ts';
2017-09-02 01:50:31 +00:00
import CustomDialog from '../components/custom_dialog';
import Modal from '../components/Modal.vue';
import {Conversation} from './interfaces';
import l from './localize';
@Component({
components: {modal: Modal}
})
export default class ConversationSettings extends CustomDialog {
@Prop({required: true})
readonly conversation!: Conversation;
2017-09-02 01:50:31 +00:00
l = l;
setting = Conversation.Setting;
notify!: Conversation.Setting;
highlight!: Conversation.Setting;
highlightWords!: string;
joinMessages!: Conversation.Setting;
defaultHighlights!: boolean;
2019-06-02 23:57:32 +00:00
ads!: string[];
2017-09-02 01:50:31 +00:00
2019-01-03 17:38:17 +00:00
load(): void {
2017-09-02 01:50:31 +00:00
const settings = this.conversation.settings;
this.notify = settings.notify;
this.highlight = settings.highlight;
this.highlightWords = settings.highlightWords.join(',');
this.joinMessages = settings.joinMessages;
2017-10-18 23:29:28 +00:00
this.defaultHighlights = settings.defaultHighlights;
2019-06-02 23:57:32 +00:00
this.ads = settings.adSettings.ads.slice(0);
if (this.ads.length === 0) {
this.ads.push('');
}
2017-09-02 01:50:31 +00:00
}
submit(): void {
this.conversation.settings = {
notify: this.notify,
highlight: this.highlight,
2019-06-02 23:57:32 +00:00
highlightWords: this.highlightWords.split(',').map((x) => x.trim()).filter((x) => (x.length > 0)),
2017-10-18 23:29:28 +00:00
joinMessages: this.joinMessages,
2019-06-02 23:57:32 +00:00
defaultHighlights: this.defaultHighlights,
adSettings: {
2019-06-03 00:42:05 +00:00
ads: this.ads.map((ad: string) => ad.trim()).filter((ad: string) => (ad.length > 0))
2019-06-02 23:57:32 +00:00
}
2017-09-02 01:50:31 +00:00
};
}
2019-06-02 23:57:32 +00:00
addAd(): void {
this.ads.push('');
}
removeAd(index: number): void {
if (confirm('Are you sure you wish to remove this ad?')) {
this.ads.splice(index, 1);
}
}
moveAdUp(index: number): void {
const ad = this.ads.splice(index, 1);
this.ads.splice(index - 1, 0, ad[0]);
}
moveAdDown(index: number): void {
const ad = this.ads.splice(index, 1);
this.ads.splice(index + 1, 0, ad[0]);
}
2017-09-02 01:50:31 +00:00
}
</script>
<style lang="scss">
.form-group.ad-list label a {
padding-right: 0.3rem;
opacity:0.3
}
.form-group.ad-list label a:hover {
opacity:0.6
}
</style>