|
| 1 | +<template> |
| 2 | + <wikibase-wbui2025-modal-overlay> |
| 3 | + <div class="wikibase-wbui2025-add-reference"> |
| 4 | + <div class="wikibase-wbui2025-add-reference-heading"> |
| 5 | + <div class="wikibase-wbui2025-add-reference-close"> |
| 6 | + <cdx-button |
| 7 | + :aria-label="$i18n( 'wikibase-cancel' )" |
| 8 | + weight="quiet" |
| 9 | + @click="$emit( 'hide' )" |
| 10 | + > |
| 11 | + <cdx-icon :icon="cdxIconClose"></cdx-icon> |
| 12 | + </cdx-button> |
| 13 | + </div> |
| 14 | + <h2>{{ $i18n( 'wikibase-addreference' ) }}</h2> |
| 15 | + </div> |
| 16 | + <div class="wikibase-wbui2025-add-reference-form"> |
| 17 | + <cdx-button |
| 18 | + action="progressive" |
| 19 | + :disabled="addButtonDisabled" |
| 20 | + @click="$emit( 'add-reference', selectedPropertyId, snakData )" |
| 21 | + > |
| 22 | + <cdx-icon :icon="cdxIconCheck"></cdx-icon> |
| 23 | + {{ $i18n( 'wikibase-add' ) }} |
| 24 | + </cdx-button> |
| 25 | + <wikibase-wbui2025-property-lookup |
| 26 | + ref="propertyLookup" |
| 27 | + @update:selected="onPropertySelection" |
| 28 | + > |
| 29 | + </wikibase-wbui2025-property-lookup> |
| 30 | + <cdx-text-input |
| 31 | + v-if="selectedPropertyDatatype === 'string'" |
| 32 | + ref="textInput" |
| 33 | + v-model.trim="snakValue" |
| 34 | + class="wikibase-wbui2025-add-reference-value" |
| 35 | + :placeholder="$i18n( 'wikibase-addreference' ).text()" |
| 36 | + > |
| 37 | + </cdx-text-input> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + </wikibase-wbui2025-modal-overlay> |
| 41 | +</template> |
| 42 | + |
| 43 | +<script> |
| 44 | +const { defineComponent, nextTick } = require( 'vue' ); |
| 45 | +const { CdxButton, CdxIcon, CdxTextInput } = require( '../../codex.js' ); |
| 46 | +const { cdxIconClose, cdxIconCheck } = require( './icons.json' ); |
| 47 | +
|
| 48 | +const WikibaseWbui2025ModalOverlay = require( './wikibase.wbui2025.modalOverlay.vue' ); |
| 49 | +const WikibaseWbui2025PropertyLookup = require( './wikibase.wbui2025.propertyLookup.vue' ); |
| 50 | +
|
| 51 | +module.exports = exports = defineComponent( { |
| 52 | + name: 'WikibaseWbui2025AddReference', |
| 53 | + components: { |
| 54 | + CdxButton, |
| 55 | + CdxIcon, |
| 56 | + CdxTextInput, |
| 57 | + WikibaseWbui2025ModalOverlay, |
| 58 | + WikibaseWbui2025PropertyLookup |
| 59 | + }, |
| 60 | + emits: [ 'hide', 'add-reference' ], |
| 61 | + data() { |
| 62 | + return { |
| 63 | + cdxIconClose, |
| 64 | + cdxIconCheck, |
| 65 | + selectedPropertyId: null, |
| 66 | + selectedPropertyDatatype: null, |
| 67 | + snakValue: '' |
| 68 | + }; |
| 69 | + }, |
| 70 | + computed: { |
| 71 | + addButtonDisabled() { |
| 72 | + return !( this.selectedPropertyId && this.snakValue ); |
| 73 | + }, |
| 74 | + snakData() { |
| 75 | + return { |
| 76 | + snaktype: 'value', |
| 77 | + property: this.selectedPropertyId, |
| 78 | + datavalue: { |
| 79 | + value: this.snakValue, |
| 80 | + type: this.selectedPropertyDatatype |
| 81 | + }, |
| 82 | + datatype: this.selectedPropertyDatatype |
| 83 | + }; |
| 84 | + } |
| 85 | + }, |
| 86 | + methods: { |
| 87 | + onPropertySelection( propertyId, propertyData ) { |
| 88 | + this.selectedPropertyId = propertyId; |
| 89 | + this.selectedPropertyDatatype = propertyData.datatype; |
| 90 | + nextTick( () => { |
| 91 | + this.$refs.textInput.focus(); |
| 92 | + } ); |
| 93 | + } |
| 94 | + }, |
| 95 | + mounted() { |
| 96 | + nextTick( () => { |
| 97 | + this.$refs.propertyLookup.focus(); |
| 98 | + } ); |
| 99 | + } |
| 100 | +} ); |
| 101 | +</script> |
| 102 | + |
| 103 | +<style lang="less"> |
| 104 | +@import 'mediawiki.skin.variables.less'; |
| 105 | +
|
| 106 | +.wikibase-wbui2025-add-reference { |
| 107 | + display: flex; |
| 108 | + flex-direction: column; |
| 109 | + align-items: flex-start; |
| 110 | + gap: @spacing-65; |
| 111 | + width: 100%; |
| 112 | + height: 100%; |
| 113 | +} |
| 114 | +
|
| 115 | +.wikibase-wbui2025-add-reference-heading { |
| 116 | + align-self: stretch; |
| 117 | + padding: @spacing-100 @spacing-100 @spacing-200; |
| 118 | + border-bottom: @border-width-base @border-style-base @border-color-subtle; |
| 119 | +
|
| 120 | + h2 { |
| 121 | + padding: @spacing-0; |
| 122 | + font-family: @font-family-base; |
| 123 | + text-align: center; |
| 124 | + color: @color-emphasized; |
| 125 | + } |
| 126 | +} |
| 127 | +
|
| 128 | +.wikibase-wbui2025-add-reference-close { |
| 129 | + text-align: right; |
| 130 | +} |
| 131 | +
|
| 132 | +.wikibase-wbui2025-add-reference-form { |
| 133 | + padding: @spacing-200 @spacing-100; |
| 134 | + align-self: stretch; |
| 135 | + display: flex; |
| 136 | + flex-direction: column; |
| 137 | + gap: @spacing-150; |
| 138 | + align-items: flex-end; |
| 139 | +} |
| 140 | +
|
| 141 | +.wikibase-wbui2025-add-reference-value { |
| 142 | + align-self: stretch; |
| 143 | +} |
| 144 | +</style> |
0 commit comments