소스 검색

Template - Communication

master
Kobus 5 년 전
부모
커밋
19692bb531

+ 80
- 17
src/components/communication/templateDetail.vue 파일 보기

@@ -8,16 +8,13 @@
8 8
         <div class="col-md-12">
9 9
           <div class="d-flex">
10 10
             <div class="p-2 mr-auto">
11
-              <h2>Detailed Item</h2>
11
+              <h2>Template - Detail</h2>
12 12
             </div>
13 13
             <div class="p-2">
14
-              <div class="btn btn-primary myBackground">Add New</div>
14
+              <div class="btn btn-primary myBackground" v-if="!editable" @click="onEdit()">Edit</div>
15 15
             </div>
16 16
             <div class="p-2">
17
-              <div class="btn btn-primary myBackground">Edit</div>
18
-            </div>
19
-            <div class="p-2">
20
-              <div class="btn btn-primary myBackground">Close</div>
17
+              <div class="btn btn-primary myBackground" @click="onClose()">Save/Close</div>
21 18
             </div>
22 19
           </div>
23 20
         </div>
@@ -32,7 +29,14 @@
32 29
                 <b>I</b>
33 30
               </span>
34 31
             </div>
35
-            <input class="form-control" type="number" step="any" name="levy" v-model="item.id" />
32
+            <input
33
+              class="form-control"
34
+              type="number"
35
+              step="any"
36
+              name="levy"
37
+              v-model="item.id"
38
+              disabled
39
+            />
36 40
           </div>
37 41
         </div>
38 42
         <div class="col-md-8 text-left">
@@ -43,7 +47,14 @@
43 47
                 <b>N</b>
44 48
               </span>
45 49
             </div>
46
-            <input class="form-control" type="text" step="any" name="levy" v-model="item.name" />
50
+            <input
51
+              class="form-control"
52
+              type="text"
53
+              step="any"
54
+              name="levy"
55
+              v-model="item.name"
56
+              :disabled="!editable"
57
+            />
47 58
           </div>
48 59
         </div>
49 60
         <div class="col-md-12">
@@ -57,7 +68,14 @@
57 68
                 <b>S</b>
58 69
               </span>
59 70
             </div>
60
-            <input class="form-control" type="text" step="any" name="levy" v-model="item.subject" />
71
+            <input
72
+              class="form-control"
73
+              type="text"
74
+              step="any"
75
+              name="levy"
76
+              v-model="item.subject"
77
+              :disabled="!editable"
78
+            />
61 79
           </div>
62 80
         </div>
63 81
         <div class="col-md-12">
@@ -112,6 +130,7 @@
112 130
                     step="any"
113 131
                     name="levy"
114 132
                     v-model="item.body"
133
+                    :disabled="!editable"
115 134
                   />
116 135
                 </div>
117 136
               </div>
@@ -135,28 +154,35 @@
135 154
               <h2>Coded Fields</h2>
136 155
             </div>
137 156
             <div class="p-2">
138
-              <div class="btn btn-primary myBackground" @click="addClose()">{{btnCaption}}</div>
157
+              <div
158
+                class="btn btn-primary myBackground"
159
+                @click="addClose()"
160
+                v-if="editable"
161
+              >{{btnCaption}}</div>
139 162
             </div>
140 163
           </div>
141 164
         </div>
142
-        <div
143
-          class="col-md-12"
144
-          v-if="showNew"
145
-          style="background-color:rgba(255,255,255,0.75); border:silver solid thin;border-radius:10px;padding:10px;padding:10px 30px;"
146
-        >
147
-          <TemplateInnerItem />
165
+        <div class="col-md-12" v-if="showNew">
166
+          <TemplateInnerItem @onItemAdd="onItemAdd" />
148 167
         </div>
149 168
         <div class="col-md-12">
150 169
           <hr />
151 170
         </div>
152 171
         <div class="col-md-12">
153
-          <ListView :items="item.placeHolders" :hideSearch="true" />
172
+          <ListView
173
+            :items="item.placeHolders"
174
+            :hideSearch="true"
175
+            :showNew="false"
176
+            :deleteable="editable"
177
+            @onDelete="onItemDelete"
178
+          />
154 179
         </div>
155 180
       </div>
156 181
     </div>
157 182
   </div>
158 183
 </template>
159 184
 <script>
185
+import { mapActions } from 'vuex';
160 186
 import ListView from '../shared/listView.vue';
161 187
 import TemplateInnerItem from './templateInnerItem.vue';
162 188
 
@@ -172,18 +198,55 @@ export default {
172 198
   },
173 199
   props: {
174 200
     item: {},
201
+    editable: {
202
+      default: false,
203
+    },
175 204
   },
176 205
   computed: {
177 206
     btnCaption() {
178 207
       return this.showNew ? 'Close' : 'New';
179 208
     },
209
+    ItemList() {
210
+      return this.item.placeHolders;
211
+    },
180 212
   },
181 213
   methods: {
214
+    ...mapActions('template', ['addItem', 'editItem']),
182 215
     addClose() {
183 216
       if (this.showNew) {
184 217
         this.showNew = false;
185 218
       } else this.showNew = true;
186 219
     },
220
+    onClose() {
221
+      if (this.item.id > 0) {
222
+        // edit
223
+        this.editItem(this.item);
224
+      } else {
225
+        // add.
226
+        this.addItem(this.item);
227
+      }
228
+      console.log(JSON.stringify(this.item));
229
+      this.$emit('onClose');
230
+    },
231
+    onItemDelete(item) {
232
+      this.item.placeHolders = _.remove(
233
+        this.item.placeHolders,
234
+        x => x !== item,
235
+      );
236
+    },
237
+    onEdit() {
238
+      this.editable = true;
239
+    },
240
+    onItemAdd(item) {
241
+      const myList = this.item.placeHolders ? this.item.placeHolders : [];
242
+      myList.push({
243
+        name: item.name,
244
+        boundTo: item.property,
245
+        boundToClassDisplay: item.class.name,
246
+        boundToClass: item.class.fullName,
247
+      });
248
+      this.item.placeHolders = myList;
249
+    },
187 250
   },
188 251
 };
189 252
 </script>

+ 26
- 1
src/components/communication/templateInnerItem.vue 파일 보기

@@ -1,5 +1,8 @@
1 1
 <template>
2 2
   <div class="row">
3
+    <div class="col-md-12" v-if="message !== undefined">
4
+      <Alert :text="message" :type="'ERROR'" />
5
+    </div>
3 6
     <div class="col-md-3">
4 7
       <input
5 8
         class="form-control"
@@ -21,19 +24,24 @@
21 24
       </select>
22 25
     </div>
23 26
     <div class="col-md-3">
24
-      <div class="btn btn-primary myBackground w-100">Add</div>
27
+      <div class="btn btn-primary myBackground w-100" @click="onItemAdd()">Add</div>
25 28
     </div>
26 29
   </div>
27 30
 </template>
28 31
 <script>
29 32
 import { mapState, mapActions } from 'vuex';
33
+import Alert from '../shared/alert.vue';
30 34
 
31 35
 export default {
36
+  components: {
37
+    Alert,
38
+  },
32 39
   mounted() {
33 40
     this.init();
34 41
   },
35 42
   data() {
36 43
     return {
44
+      message: undefined,
37 45
       item: {
38 46
         name: undefined,
39 47
         class: undefined,
@@ -49,6 +57,23 @@ export default {
49 57
     onClassChanged() {
50 58
       this.getProperties(this.item.class);
51 59
     },
60
+    onItemAdd() {
61
+      let msg = '';
62
+      if (this.item.name === undefined) {
63
+        msg += 'Please give a name...';
64
+      }
65
+      if (this.item.class == undefined) {
66
+        msg += 'Please choose a class...';
67
+      }
68
+      if (this.item.property == undefined) {
69
+        msg += 'Please choose a property...';
70
+      }
71
+      if (msg.length > 0) {
72
+        this.message = msg;
73
+      } else {
74
+        this.$emit('onItemAdd', this.item);
75
+      }
76
+    },
52 77
   },
53 78
 };
54 79
 </script>

+ 11
- 3
src/components/communication/templatePage.vue 파일 보기

@@ -13,10 +13,10 @@
13 13
     </div>
14 14
     <div class="row">
15 15
       <div :class="listClass">
16
-        <ListView :items="list" @onRowClick="onRowClick" />
16
+        <ListView :items="list" @onRowClick="onRowClick" @onNew="onNew" :showNew="true" />
17 17
       </div>
18 18
       <div class="col-md-6" v-if="showDetailView">
19
-        <DetailView :item="detailItem" />
19
+        <DetailView :item="detailItem" @onClose="onDetailClose" :editable="clickedNew" />
20 20
       </div>
21 21
     </div>
22 22
 
@@ -33,6 +33,7 @@ export default {
33 33
   data() {
34 34
     return {
35 35
       detailItem: undefined,
36
+      clickedNew: false,
36 37
     };
37 38
   },
38 39
   components: {
@@ -56,8 +57,15 @@ export default {
56 57
   methods: {
57 58
     ...mapActions('template', ['getList']),
58 59
     onRowClick(item) {
59
-      console.log(item);
60 60
       this.detailItem = item;
61
+      this.clickedNew = false;
62
+    },
63
+    onNew() {
64
+      this.detailItem = {};
65
+      this.clickedNew = true;
66
+    },
67
+    onDetailClose() {
68
+      this.detailItem = undefined;
61 69
     },
62 70
   },
63 71
 };

+ 11
- 2
src/components/shared/listView.vue 파일 보기

@@ -2,10 +2,13 @@
2 2
 /* eslint-disable guard-for-in */
3 3
 <template>
4 4
   <div>
5
-    <div class="d-flex justify-content-between" v-if="!hideSearch">
6
-      <div class="p-2">
5
+    <div class="d-flex justify-content-between">
6
+      <div class="p-2" v-if="!hideSearch">
7 7
         <input v-model="searchItem" class="form-control" placeholder="Search ..." />
8 8
       </div>
9
+      <div class="p-2" v-if="showNew">
10
+        <div class="btn btn-primary myBackground" @click="onNew()">New</div>
11
+      </div>
9 12
     </div>
10 13
     <div v-if="items && items.length > 0">
11 14
       <table id="table" class="table table-bordered table-hover">
@@ -96,6 +99,9 @@ export default {
96 99
     hideSearch: {
97 100
       default: false,
98 101
     },
102
+    showNew: {
103
+      default: true,
104
+    },
99 105
     items: undefined,
100 106
     editable: {
101 107
       default: false,
@@ -119,6 +125,9 @@ export default {
119 125
     };
120 126
   },
121 127
   methods: {
128
+    onNew() {
129
+      this.$emit('onNew');
130
+    },
122 131
     isObject(item) {
123 132
       return !!item && item.constructor === Object;
124 133
     },

+ 1
- 1
src/components/timeshare/sell/sellPage.vue 파일 보기

@@ -296,7 +296,7 @@
296 296
                 </div>
297 297
               </div>
298 298
             </div>
299
-            <DetailIndividual :currentUser="sellItem.owner" :showBank="true" />
299
+            <DetailIndividual :currentUser="sellItem.owner" :showBank="true" :showAddress="true" />
300 300
             <hr />
301 301
           </div>
302 302
           <br />

+ 17
- 0
src/store/modules/communication/template.js 파일 보기

@@ -5,6 +5,7 @@ export default {
5 5
   state: {
6 6
     list: [],
7 7
     item: {},
8
+    message: undefined,
8 9
   },
9 10
   mutations: {
10 11
     setList(state, list) {
@@ -21,5 +22,21 @@ export default {
21 22
         .then(result => commit('setList', result.data))
22 23
         .catch(console.error);
23 24
     },
25
+    addItem({
26
+      dispatch,
27
+    }, item) {
28
+      axios
29
+        .post('/api/template', item)
30
+        .then(() => dispatch('getList'))
31
+        .catch(console.error);
32
+    },
33
+    editItem({
34
+      dispatch,
35
+    }, item) {
36
+      axios
37
+        .put(`/api/template/${item.id}`, item)
38
+        .then(() => dispatch('getList'))
39
+        .catch(console.error);
40
+    },
24 41
   },
25 42
 };

Loading…
취소
저장