GridEditorDefaultSource.vue 4.2 KB
Newer Older
Anton's avatar
Intial  
Anton committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<template lang="pug">

  q-list.default-source-container

    q-list-header
      q-item
        small Standard Cell Types

    q-item-separator

    template(v-for="(item, i) in items")

      template(v-if="i > 0")
        q-item-separator

      q-item(
        draggable="true",
        @dragstart.native="event => {handleItemDragStart(event, item)}")
        q-field(
          :icon="typeToIconName(item.type)",
          :helper="item.help",
          :error="item.error",
          :error-label="item.errorMessage",
          style="width: 100%")
          q-input(
            :float-label="item.label",
            :type="item.inputType",
            :min-rows="1",
            :max-height="500",
            :value="item.value",
            :model="item.value",
            @input="value => {handleItemChanged(value, item)}",
            @change="value => {handleItemChanged(value, item)}")

</template>

<script>

  const typeToIconName = {
    'image': 'photo',
    'iframe': 'picture in picture',
    'internal-link': 'link',
    'video': 'local movies',
    'text': 'subject',
    'title': 'title'
  }

  export default {
    data () {
      return {
        items: [
          {
            inputType: 'text',
            type: 'Title',
            label: 'Title Cell',
56
            component: 'CellTitle',
Anton's avatar
Intial  
Anton committed
57
58
59
60
61
62
63
64
65
            help: '',
            error: false,
            errorMessage: '',
            value: ''
          },
          {
            inputType: 'textarea',
            type: 'Text',
            label: 'Text Cell',
66
            component: 'CellText',
Anton's avatar
Intial  
Anton committed
67
68
69
70
71
72
73
74
75
            help: '',
            error: false,
            errorMessage: '',
            value: ''
          },
          {
            inputType: 'url',
            type: 'Video',
            label: 'Video Cell',
76
            component: 'CellVideo',
Anton's avatar
Intial  
Anton committed
77
78
79
80
81
82
83
84
85
            help: 'Insert a URL to: a video file or a Vimeo / YouTube video page',
            error: false,
            errorMessage: 'Needs to be a valid URL',
            value: ''
          },
          {
            inputType: 'url',
            type: 'Image',
            label: 'Image Cell',
86
            component: 'CellImage',
Anton's avatar
Intial  
Anton committed
87
88
89
90
91
92
93
94
95
            help: 'Insert a URL to an image file',
            error: false,
            errorMessage: 'Needs to be a valid URL',
            value: ''
          },
          {
            inputType: 'url',
            type: 'Internal-Link',
            label: 'Link Cell',
96
            component: 'CellInternalLink',
Anton's avatar
Intial  
Anton committed
97
98
99
100
101
102
103
104
105
            help: 'Insert a URL to a page in this system',
            error: false,
            errorMessage: 'Needs to be a valid URL',
            value: ''
          },
          {
            inputType: 'url',
            type: 'IFrame',
            label: 'IFrame Cell',
106
            component: 'CellIFrame',
Anton's avatar
Intial  
Anton committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
            help: 'Insert some URL',
            error: false,
            errorMessage: 'Needs to be a valid URL',
            value: ''
          }
        ]
      }
    },
    methods: {
      typeToIconName (type) {
        let iconName = typeToIconName[type.toLowerCase()]
        if (!iconName) {
          iconName = 'broken image'
        }
        return iconName
      },
      handleItemDragStart (event, item) {
        // FIXME: manually setting the item.value because data-binding fails for some reason and change is triggered too late (after drag started)
        const inputField = event.target.querySelector('input')
        if (inputField) {
          inputField.blur()
          this.handleItemChanged(inputField.value, item)
        }
        const resourceCell = {
131
132
133
          data: { content: item.value },
          config: {},
          component: item.component
Anton's avatar
Intial  
Anton committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
        }
        event.dataTransfer.setData('text/plain', JSON.stringify(resourceCell))
      },
      handleItemChanged (value, item) {
        if (item.inputType !== 'url') {
          item.value = value
        }
        else {
          item.error = !(/^http[s]?:\/\/.+/.test(value))
          if (!item.error) {
            item.value = value
          }
        }
      }
    }
  }
</script>

<style scoped lang="stylus">

  .q-list-header
    padding-left 0

    .q-input
      padding-left 1em
      padding-right 1em

    .q-input:before
    .q-input:after
      display none

  .q-input
    padding-left 0

</style>