vue_crud 0.1.10.8.4 → 0.1.10.8.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,32 +1,38 @@
1
1
  <script type="text/javascript">
2
2
  if(column_type === undefined) var column_type = 'card';
3
- if(suffix === undefined) var suffix = '.json';
4
3
  if(countOfPage === undefined) var countOfPage = 9;
5
4
  if(sortable === undefined) var sortable = false;
6
5
  if(info_url === undefined) var info_url = "http://localhost:3000/service_prototypes/info";
7
6
  $(document).ready(function() {
8
7
  var modal = $($('#modal').html());
9
8
  var models = $($('#models-' + column_type).html());
10
- modal.find('.vue_form').html(
11
- $('#vue_form').html()
12
- );
9
+
13
10
  models.find('.custom_models').html(
14
11
  $('#custom_models').html()
15
12
  );
16
13
  models.find('.custom_action').html(
17
14
  $('#custom_action').html()
18
15
  );
16
+ modal.find('.modal_body_prepend').html(
17
+ $('#modal_body_prepend').html()
18
+ );
19
+ modal.find('.modal_body_append').html(
20
+ $('#modal_body_append').html()
21
+ );
19
22
  modal.find('.custom_modal_body').html(
20
23
  $('#custom_modal_body').html()
21
24
  );
22
25
  modal.find('.custom_modal_action').html(
23
26
  $('#custom_modal_action').html()
24
27
  );
28
+
25
29
  $('#modal').html(modal);
26
30
  $('#models-' + column_type).html(models);
31
+ $('.vue_form').html(
32
+ $('#vue_form').html()
33
+ );
27
34
  vueCRUD_init({
28
35
  column_type: column_type,
29
- suffix: suffix,
30
36
  countOfPage: countOfPage,
31
37
  sortable: sortable,
32
38
  info_url: info_url
@@ -80,7 +86,7 @@ $(document).ready(function() {
80
86
  <div class="ui divider" v-if="column_type == 'card'"></div>
81
87
  <!-- NOTE: models -->
82
88
  <div v-sortable class="ui three column grid" v-if="column_type == 'card'">
83
- <models v-for="model in filteredModels" :model="model" :info="info" :selected_attribute="selected_attribute"></models>
89
+ <models v-for="model in filteredModels" :original_model="model" :info="info" :selected_attribute="selected_attribute"></models>
84
90
  </div>
85
91
 
86
92
  <table class="ui celled selectable table" v-if="column_type == 'table'">
@@ -96,7 +102,7 @@ $(document).ready(function() {
96
102
  </tr>
97
103
  </thead>
98
104
  <tbody v-sortable>
99
- <tr is="models" v-for="model in filteredModels" :model="model" :info="info" :selected_attribute="selected_attribute">
105
+ <tr is="models" v-for="model in filteredModels" :original_model="model" :info="info" :selected_attribute="selected_attribute">
100
106
  </tr>
101
107
  </tbody>
102
108
  <tfoot>
@@ -126,18 +132,24 @@ $(document).ready(function() {
126
132
  <div class="ui inverted dimmer">
127
133
  <div class="ui indeterminate text loader">處理中...</div>
128
134
  </div>
129
- <div class="header">{{ action_name }} {{ info.titles.display_name }}</div>
135
+ <div class="header">{{ action_name }}</div>
130
136
  <div class="content">
137
+ <!-- NOTE: Modal body prepend -->
138
+ <div v-show="defaultMode" class="modal_body_prepend"></div>
131
139
  <!-- NOTE: Not customMode -->
132
- <div v-show="!customMode" class="vue_form"></div>
133
- <!-- NOTE: Is customMode -->
140
+ <div v-show="defaultMode" class="vue_form"></div>
141
+ <!-- NOTE: Modal body prepend -->
142
+ <div v-show="defaultMode" class="modal_body_append"></div>
143
+
134
144
  <!-- NOTE: Custom modal body -->
135
- <div v-show="customMode"><div class="custom_modal_body"></div></div>
145
+ <div v-show="!defaultMode">
146
+ <div class="custom_modal_body"></div>
147
+ </div>
136
148
  </div>
137
149
  <div class="actions">
138
150
  <button class="ui basic gray cancel button">取消</button>
139
- <button @click="toggleUpdate" class="ui button blue" v-show="!customMode && editMode">更新</button>
140
- <button @click="toggleCreate" class="ui button blue" v-show="!customMode && newMode">創建</button>
151
+ <button @click="modalSubmit" class="ui button blue">{{ action_name }}</button>
152
+ <!-- <button @click="toggleCreate" class="ui button blue" v-show="newAction">{{ action_name }}</button> -->
141
153
  <!-- NOTE: Custom modal action -->
142
154
  <div class="inline-block custom_modal_action"></div>
143
155
  </div>
@@ -173,7 +185,7 @@ $(document).ready(function() {
173
185
 
174
186
  <!-- NOTE: Custom action -->
175
187
  <div class="inline-block custom_action"></div>
176
- <div class="ui animated fade blue button" @click="openModal('編輯')" tabindex="0">
188
+ <div class="ui animated fade blue button" @click="editModel('編輯')" tabindex="0">
177
189
  <div class="visible content">編輯</div>
178
190
  <div class="hidden content">
179
191
  <i class="right edit icon"></i>
@@ -196,29 +208,37 @@ $(document).ready(function() {
196
208
  <div class="column">
197
209
  <div class="ui fluid card sort-here">
198
210
  <div class="content">
211
+ <div class="ui top attached label gray">{{ info.titles.display_name }}</div>
199
212
  <div class="header">{{ model[info.titles.title_attribute] }}</div>
200
- <div class="meta">{{ info.titles.display_name }}</div>
201
- <div class="ui divider"></div>
202
- <div class="description">
203
- <div class="ui small feed" v-for="attribute in info.model_attributes" v-if="attribute.visible">
204
- <div class="event">
205
- <div class="content">
206
- <div class="summary" :class="{highlight: attribute.name == selected_attribute}">
207
- <span v-if="attribute.input_type != 'img'">
208
- <div class="ui teal horizontal label">{{ attribute.display_name }}</div>
209
- <br>
210
- {{ model[attribute.name] }}
211
- </span>
212
- <span v-else>
213
- <img :src="model[attribute.name]" />
214
- </span>
215
- </div>
216
- </div>
213
+ <div class="meta">創建於 {{ model[info.titles.created_at_attribute] | datetime }}</div>
214
+ <div class="ui horizontal divider" v-toggle><h3><i class="bar chart icon"></i>欄位資料</h3></div>
215
+ <div class="description attribute">
216
+ <div class="item" v-for="attribute in info.model_attributes" v-if="attribute.visible" :class="{highlight: attribute.name == selected_attribute}">
217
+ <div v-if="attribute.input_type == 'token'">
218
+ <span class="display_name">{{ attribute.display_name }}:</span>
219
+ <pre>{{ model[attribute.name] }}</pre>
220
+ </div>
221
+ <div v-else-if="attribute.input_type == 'checkbox'">
222
+ <span class="display_name">{{ attribute.display_name }}:</span>
223
+ {{ model[attribute.name] | boolean }}
224
+ </div>
225
+ <div v-else-if="attribute.input_type == 'email'">
226
+ <span class="display_name">{{ attribute.display_name }}:</span>
227
+ <a :href="'mailto:' + model[attribute.name]" target="new">{{ model[attribute.name] }}</a>
217
228
  </div>
229
+ <div v-else-if="attribute.input_type == 'img'">
230
+ <span class="display_name">{{ attribute.display_name }}:</span>
231
+ <img :src="model[attribute.name]" />
232
+ </div>
233
+ <div v-else>
234
+ <span class="display_name">{{ attribute.display_name }}:</span>
235
+ {{ model[attribute.name] }}
236
+ </div>
237
+ <div class="ui divider"></div>
218
238
  </div>
219
239
  <!-- NOTE: Custom models -->
220
- <div class="custom_models"></div>
221
240
  </div>
241
+ <div class="custom_models"></div>
222
242
  </div>
223
243
  <div class="extra content">
224
244
  <div class="ui red right ribbon label" v-show="is_deleted">您已刪除,點擊<a href="#" @click="restoreModel" onclick="return false" class="save_now">復原</a></div>
@@ -228,7 +248,7 @@ $(document).ready(function() {
228
248
  <div class="ui divider"></div>
229
249
  <!-- NOTE: Custom action -->
230
250
  <div class="inline-block custom_action"></div>
231
- <div class="ui animated fade blue button" @click="openModal('編輯')" tabindex="0">
251
+ <div class="ui animated fade blue button" @click="editModel('編輯')" tabindex="0">
232
252
  <div class="visible content">編輯</div>
233
253
  <div class="hidden content">
234
254
  <i class="right edit icon"></i>
@@ -249,8 +269,8 @@ $(document).ready(function() {
249
269
  </div>
250
270
  </script>
251
271
  <script type="text/x-template" id="vue_form">
252
- <form class="ui form" v-if="newMode || editMode">
253
- <div v-for="attribute in info.model_attributes" v-if="attribute.editable">
272
+ <form class="ui form">
273
+ <div v-for="attribute in model_attributes" v-if="attribute.editable">
254
274
  <div class="field" v-if="attribute.input_type == 'select'">
255
275
  <label :for="'model_' + attribute.display_name">{{ attribute.display_name }}</label>
256
276
  <select :id="'model_' + attribute.display_name" v-model="model[attribute.name]" class="ui fluid dropdown" :class="attribute.input_class">
@@ -262,7 +282,7 @@ $(document).ready(function() {
262
282
  </span>
263
283
  </div>
264
284
  </div>
265
- <div class="field" v-if="attribute.input_type == 'multiSelect'">
285
+ <div class="field" v-else-if="attribute.input_type == 'multiSelect'">
266
286
  <label :for="'model_' + attribute.display_name">{{ attribute.display_name }}</label>
267
287
  <select :id="'model_' + attribute.display_name" multiple v-model="model[attribute.name]" class="ui fluid dropdown" :class="attribute.input_class">
268
288
  <option v-for="option in attribute.options" :value="option.value" v-text="option.text"></option>
@@ -273,7 +293,25 @@ $(document).ready(function() {
273
293
  </span>
274
294
  </div>
275
295
  </div>
276
- <div class="field" v-if="attribute.input_type == 'textarea'">
296
+ <div class="field" v-else-if="attribute.input_type == 'selectInput'">
297
+ <label :for="'model_' + attribute.display_name">{{ attribute.display_name }}</label>
298
+ <div class="ui grid">
299
+ <div class="ten wide column">
300
+ <input type="text" :id="'model_' + attribute.display_name" v-model="model[attribute.name]" :class="attribute.input_class">
301
+ </div>
302
+ <div class="six wide column">
303
+ <select v-model="model[attribute.name]" class="ui dropdown" :class="attribute.input_class" onchange="$(this).parent().prev().find('input').val(this.value)">
304
+ <option v-for="option in attribute.options" :value="option.value" v-text="option.text"></option>
305
+ </select>
306
+ </div>
307
+ </div>
308
+ <div class="ui pointing red basic label" v-show="errors[attribute.name]">
309
+ <span style="color: red" v-for="(error, index) in errors[attribute.name]">
310
+ <span v-if="index > 0">,</span> {{ error }}
311
+ </span>
312
+ </div>
313
+ </div>
314
+ <div class="field" v-else-if="attribute.input_type == 'textarea'">
277
315
  <label :for="'model_' + attribute.display_name">{{ attribute.display_name }}</label>
278
316
  <textarea v-froala :attribute="attribute.name" :id="'model_' + attribute.display_name" v-model="model[attribute.name]" :class="attribute.input_class"></textarea>
279
317
  <div class="ui pointing red basic label" v-show="errors[attribute.name]">
@@ -282,7 +320,7 @@ $(document).ready(function() {
282
320
  </span>
283
321
  </div>
284
322
  </div>
285
- <div class="field" v-if="attribute.input_type == 'checkbox'">
323
+ <div class="field" v-else-if="attribute.input_type == 'checkbox'">
286
324
  <div class="ui toggle checkbox">
287
325
  <input type="checkbox" tabindex="0" class="hidden" :id="'model_' + attribute.display_name" v-model="model[attribute.name]" :class="attribute.input_class">
288
326
  <label>{{ attribute.display_name }}</label>
@@ -293,7 +331,7 @@ $(document).ready(function() {
293
331
  </span>
294
332
  </div>
295
333
  </div>
296
- <div class="field" v-if="attribute.input_type == 'number'">
334
+ <div class="field" v-else-if="attribute.input_type == 'number'">
297
335
  <label :for="'model_' + attribute.display_name">{{ attribute.display_name }}</label>
298
336
  <input type="number" :id="'model_' + attribute.display_name" v-model="model[attribute.name]" :class="attribute.input_class" number>
299
337
  <div class="ui pointing red basic label" v-show="errors[attribute.name]">
@@ -302,7 +340,7 @@ $(document).ready(function() {
302
340
  </span>
303
341
  </div>
304
342
  </div>
305
- <div class="field" v-if="attribute.input_type != 'number' && attribute.input_type != 'select' && attribute.input_type != 'multiSelect' && attribute.input_type != 'textarea' && attribute.input_type != 'checkbox'">
343
+ <div class="field" v-else>
306
344
  <label :for="'model_' + attribute.display_name">{{ attribute.display_name }}</label>
307
345
  <input :type="attribute.input_type" :id="'model_' + attribute.display_name" v-model="model[attribute.name]" :class="attribute.input_class">
308
346
  <div class="ui pointing red basic label" v-show="errors[attribute.name]">
@@ -1,3 +1,3 @@
1
1
  module VueCrud
2
- VERSION = "0.1.10.8.4"
2
+ VERSION = "0.1.10.8.5"
3
3
  end
@@ -1,8 +1,10 @@
1
- $.FE.prototype.reset = function () {
2
- this.$el.html('');
3
- }
4
- $.FE.prototype.refresh = function () {
5
- this.$el.html(this.$oel.val());
1
+ if($.FE !== undefined) {
2
+ $.FE.prototype.reset = function () {
3
+ this.$el.html('');
4
+ }
5
+ $.FE.prototype.refresh = function () {
6
+ this.$el.html(this.$oel.val());
7
+ }
6
8
  }
7
9
  $(document).ajaxStart(function() { Pace.restart(); });
8
10
  Vue.config.devtools = true;
@@ -10,16 +12,39 @@ Pace.on('done', function() {
10
12
  $('#form-progress').val('0');
11
13
  });
12
14
  var event_hub = new Vue();
15
+ var modal_mixin = {};
16
+ var models_mixin = {};
17
+ var root_mixin = {};
13
18
  function sleep(time) {
14
19
  return new Promise((resolve) => setTimeout(resolve, time));
15
20
  }
16
21
  function obj_to_json(obj) {
17
22
  return JSON.parse(JSON.stringify(obj));
18
23
  }
19
- var modal_mixin = {}
20
- var models_mixin = {}
21
- var root_mixin = {}
22
-
24
+ // Array.prototype.find_and_replace = function(id, new_obj){
25
+ // for(var n = 0; n < this.length; n++) {
26
+ // var current_id = this[n].id || this[n].ID;
27
+ // if(current_id == id){
28
+ // console.log(this[n]);
29
+ // this[n] = new_obj;
30
+ // return true;
31
+ // }
32
+ // }
33
+ // return false;
34
+ // };
35
+ function urlParser(url, obj) {
36
+ var parser = document.createElement('a');
37
+ parser.href = url;
38
+ parser.parameters = parser.pathname.split('/').filter(function (str) {
39
+ return str.match(':');
40
+ });
41
+ var url = parser.protocol + "//" + parser.host;
42
+ $.each(parser.parameters, function(i, key){
43
+ parser.pathname = parser.pathname.replace(key, obj[key.replace(":", "")]);
44
+ });
45
+ url += parser.pathname + location.search;
46
+ return url;
47
+ }
23
48
  function removeParam(key, sourceURL) {
24
49
  var rtn = sourceURL.split("?")[0],
25
50
  param,
@@ -68,8 +93,10 @@ function vueCRUD_init(params = {}) {
68
93
  Vue.filter('datetime', function (value) {
69
94
  return new Date(value).toLocaleString();
70
95
  })
96
+ Vue.filter('boolean', function (value) {
97
+ return value? '是':'否';
98
+ })
71
99
  var default_options = {
72
- suffix: '.json',
73
100
  column_type: 'card',
74
101
  countOfPage: 9,
75
102
  sortable: false,
@@ -99,49 +126,44 @@ function vueCRUD_init(params = {}) {
99
126
  }
100
127
  }
101
128
  })
129
+ Vue.directive('toggle', {
130
+ inserted: function (el) {
131
+ $(el).css('cursor', 'pointer').click(function(){
132
+ $(this).next().toggle();
133
+ });
134
+ }
135
+ })
102
136
  var modalComponent = Vue.component('modal', {
103
137
  mixins: [modal_mixin],
104
138
  template: '#modal',
105
- props: {
106
- info: Object
107
- },
108
139
  data: function() {
109
140
  return {
141
+ model_attributes: [],
110
142
  errors: {},
111
143
  model: {},
112
144
  action_name: '',
113
- customMode: false,
114
- editMode: false,
115
- newMode: false
145
+ defaultMode: true
116
146
  }
117
147
  },
118
148
  mounted: function() {
149
+ // Sync errors and model from modelsComponent
119
150
  event_hub.$on('update_error', function(errors) {
120
151
  this.errors = errors;
121
152
  }.bind(this));
122
- event_hub.$on('update_action_name', function(action_name) {
123
- this.action_name = action_name;
153
+ event_hub.$on('update_model_attributes', function(model_attributes) {
154
+ this.model_attributes = model_attributes;
124
155
  }.bind(this));
125
156
  event_hub.$on('update_model', function(model) {
126
157
  this.model = model;
127
158
  }.bind(this));
128
- event_hub.$on('toggle_mode', function(mode) {
129
- if(mode == 'new') {
130
- this.newMode = true;
131
- this.editMode = false;
132
- this.customMode = false;
133
- }
134
- else if(mode == 'edit') {
135
- this.newMode = false;
136
- this.editMode = true;
137
- this.customMode = false;
138
- }
139
- else if(mode == 'custom') {
140
- this.customMode = true;
141
- this.newMode = false;
142
- this.editMode = false;
143
- }
159
+ // Modes and Actions
160
+ event_hub.$on('change_mode', function(mode, boolean) {
161
+ this[mode] = boolean;
162
+ }.bind(this));
163
+ event_hub.$on('update_action_name', function(action_name) {
164
+ this.action_name = action_name;
144
165
  }.bind(this));
166
+ // Modal actions
145
167
  event_hub.$on('openModal', function() {
146
168
  this.openModal();
147
169
  }.bind(this));
@@ -154,16 +176,14 @@ function vueCRUD_init(params = {}) {
154
176
  event_hub.$on('dimmerOff', function() {
155
177
  this.dimmerOff();
156
178
  }.bind(this));
179
+ // For froalaEditor
157
180
  event_hub.$on('changeValue', function(el) {
158
181
  this.model[$(el).attr('attribute')] = $(el).val();
159
182
  }.bind(this));
160
183
  },
161
184
  methods: {
162
- toggleCreate: function() {
163
- event_hub.$emit('toggleCreate');
164
- },
165
- toggleUpdate: function() {
166
- event_hub.$emit('toggleUpdate');
185
+ modalSubmit: function() {
186
+ event_hub.$emit('modalSubmit');
167
187
  },
168
188
  dimmerOn: function() {
169
189
  $(this.$el).find('.dimmer').addClass('active');
@@ -172,6 +192,7 @@ function vueCRUD_init(params = {}) {
172
192
  $(this.$el).find('.dimmer').removeClass('active');
173
193
  },
174
194
  openModal: function() {
195
+ event_hub.$off('modalSubmit');
175
196
  var that = this;
176
197
  $(this.$el).modal({
177
198
  observeChanges: true,
@@ -187,9 +208,7 @@ function vueCRUD_init(params = {}) {
187
208
  $('.needRefresh').froalaEditor('refresh');
188
209
  },
189
210
  onHide: function() {
190
- event_hub.$emit('cancel_customMode');
191
- event_hub.$off('toggleCreate');
192
- event_hub.$off('toggleUpdate');
211
+ event_hub.$emit('modalClose');
193
212
  that.dimmerOff();
194
213
  if(typeof modalClose !== "undefined") modalClose(this);
195
214
  }
@@ -207,12 +226,13 @@ function vueCRUD_init(params = {}) {
207
226
  mixins: [models_mixin],
208
227
  template: '#models-' + options.column_type,
209
228
  props: {
210
- model: Object,
229
+ original_model: Object,
211
230
  selected_attribute: String,
212
231
  info: Object
213
232
  },
214
233
  data: function() {
215
234
  return {
235
+ model: {},
216
236
  progress: '0',
217
237
  errors: {},
218
238
  modified: false,
@@ -237,12 +257,10 @@ function vueCRUD_init(params = {}) {
237
257
  }
238
258
  },
239
259
  mounted: function() {
260
+ this.model = this.original_model;
240
261
  event_hub.$on('update_progress', function(progress) {
241
262
  this.progress = progress;
242
263
  }.bind(this));
243
- event_hub.$on('cancel_customMode', function() {
244
- this.customMode = false;
245
- }.bind(this));
246
264
  event_hub.$on('updateSort', function(progress) {
247
265
  if($(this.$el).is(":visible")) {
248
266
  var sort = ($(this.$el).index() + 1);
@@ -255,21 +273,25 @@ function vueCRUD_init(params = {}) {
255
273
  }.bind(this));
256
274
  },
257
275
  methods: {
258
- openModal: function(action_name) {
259
- event_hub.$emit('update_action_name', action_name);
276
+ editModel: function(action_name) {
277
+ var url = this.info.actions.delete.url;
278
+ event_hub.$emit('openModal');
279
+ event_hub.$emit('update_model_attributes', this.info.model_attributes);
260
280
  event_hub.$emit('update_model', this.model);
261
- event_hub.$emit('toggle_mode', 'edit');
262
- event_hub.$on('toggleUpdate', function() {
281
+ event_hub.$emit('update_action_name', action_name + this.info.titles.display_name);
282
+
283
+ // Bind modalSubmit when modalComponent submit
284
+ // It will be off when modal close
285
+ event_hub.$on('modalSubmit', function() {
263
286
  this.updateModel();
264
287
  }.bind(this));
265
- event_hub.$emit('openModal');
266
288
  },
267
289
  restoreModel: function() {
268
290
  var that = this;
269
291
  $.ajax({
270
- method: 'POST',
292
+ method: that.info.actions.create.method,
271
293
  data: obj_to_json(that.model),
272
- url: that.info.url_prefix + options.suffix + location.search,
294
+ url: urlParser(that.info.actions.create.url, that.model),
273
295
  success: function(res) {
274
296
  that.model = res;
275
297
  that.deleteMode = false;
@@ -286,37 +308,15 @@ function vueCRUD_init(params = {}) {
286
308
  }
287
309
  });
288
310
  },
289
- // restoreModel: function() {
290
- // if(confirm("Are you sure?") == true) {
291
- // event_hub.$emit('restoreCreate', this.model);
292
- // }
293
- // else {
294
- //
295
- // }
296
- // },
297
311
  deleteModel: function () {
298
312
  var that = this;
299
- that.deleteMode = true;
300
- var id = that.model.ID || that.model.id;
301
313
  if(confirm("Are you sure?") == true) {
314
+ that.deleteMode = true;
302
315
  $.ajax({
303
- method: 'DELETE',
304
- url: that.info.url_prefix + '/' + id + options.suffix + location.search,
316
+ method: that.info.actions.delete.method,
317
+ url: urlParser(that.info.actions.delete.url, that.model),
305
318
  success: function(res) {
306
319
  that.is_deleted = true;
307
- // event_hub.$on('toggleRestoreSuccess', function() {
308
- // that.deleteMode = false;
309
- // that.is_deleted = false;
310
- // that.is_success = true;
311
- // sleep(1500).then(() => {
312
- // that.is_success = false;
313
- // });
314
- // }.bind(this));
315
- // event_hub.$on('toggleRestoreFail', function() {
316
- // that.is_deleted = false;
317
- // that.is_restore_failed = true;
318
- // alert('復原失敗,請記錄資料並重新建立');
319
- // }.bind(this));
320
320
  },
321
321
  error: function(res) {
322
322
  that.deleteMode = false;
@@ -329,12 +329,13 @@ function vueCRUD_init(params = {}) {
329
329
  },
330
330
  updateModel: function() {
331
331
  var that = this;
332
- var id = that.model.ID || that.model.id;
333
332
  $.ajax({
334
- method: 'PATCH',
333
+ method: that.info.actions.update.method,
335
334
  data: obj_to_json(that.model),
336
- url: that.info.url_prefix + '/' + id + options.suffix + location.search,
335
+ url: urlParser(that.info.actions.update.url, that.model),
337
336
  beforeSend: function() {
337
+ console.log(obj_to_json(that.model));
338
+
338
339
  event_hub.$emit('dimmerOn');
339
340
  $('.progress-bar').css('width', '0');
340
341
  },
@@ -389,7 +390,7 @@ function vueCRUD_init(params = {}) {
389
390
  success: function(res) {
390
391
  that.info = res;
391
392
  that.model = {};
392
- var default_url = that.info.url_prefix + location.search;
393
+ var default_url = that.info.actions.index.url + location.search;
393
394
  default_url = removeParam("p", default_url);
394
395
  default_url = removeParam("q", default_url);
395
396
  default_url = removeParam("mp", default_url);
@@ -397,7 +398,7 @@ function vueCRUD_init(params = {}) {
397
398
  default_url = removeParam("st", default_url);
398
399
  that.default_url = default_url;
399
400
  $.ajax({
400
- url: that.info.url_prefix + options.suffix + location.search,
401
+ url: urlParser(that.info.actions.index.url, that.model),
401
402
  success: function(res) {
402
403
  that.models = res;
403
404
  }
@@ -451,9 +452,9 @@ function vueCRUD_init(params = {}) {
451
452
  return String(model[that.selected_attribute]).indexOf(that.searchQuery) !== -1;
452
453
  });
453
454
 
454
- that.filteredModelCount = result.length
455
+ that.filteredModelCount = result.length;
455
456
  setTimeout(function () {
456
- that.is_calculating = false
457
+ that.is_calculating = false;
457
458
  }, 500)
458
459
  return result.slice(
459
460
  that.pageStart,
@@ -462,21 +463,21 @@ function vueCRUD_init(params = {}) {
462
463
  }
463
464
  },
464
465
  watch: {
465
- searchQuery: function () {
466
- this.currentPage = 1;
467
- updateQueryStringParam('q', this.searchQuery);
468
- updateQueryStringParam('p', 1);
469
- }
466
+ searchQuery: function () {
467
+ this.currentPage = 1;
468
+ updateQueryStringParam('q', this.searchQuery);
469
+ updateQueryStringParam('p', 1);
470
+ }
470
471
  },
471
472
  methods: {
472
473
  addModel: function(action_name) {
473
- event_hub.$emit('update_action_name', action_name);
474
+ event_hub.$emit('openModal');
475
+ event_hub.$emit('update_model_attributes', this.info.model_attributes);
474
476
  event_hub.$emit('update_model', this.model);
475
- event_hub.$emit('toggle_mode', 'new');
476
- event_hub.$on('toggleCreate', function() {
477
+ event_hub.$emit('update_action_name', action_name + this.info.titles.display_name);
478
+ event_hub.$on('modalSubmit', function() {
477
479
  this.createModel();
478
480
  }.bind(this));
479
- event_hub.$emit('openModal');
480
481
  },
481
482
  setPage: function(idx){
482
483
  if( idx <= 0 || idx > this.totalPage ){
@@ -485,26 +486,12 @@ function vueCRUD_init(params = {}) {
485
486
  this.currentPage = idx;
486
487
  updateQueryStringParam('p', this.currentPage);
487
488
  },
488
- // restoreModel: function () {
489
- // var that = this;
490
- // $.ajax({
491
- // method: 'POST',
492
- // data: obj_to_json(that.model),
493
- // url: that.info.url_prefix + options.suffix + location.search,
494
- // success: function(res) {
495
- // event_hub.$emit('toggleRestoreSuccess');
496
- // },
497
- // error: function(res) {
498
- // event_hub.$emit('toggleRestoreFail');
499
- // }
500
- // });
501
- // },
502
489
  createModel: function () {
503
490
  var that = this;
504
491
  $.ajax({
505
- method: 'POST',
492
+ method: that.info.actions.create.method,
506
493
  data: obj_to_json(that.model),
507
- url: that.info.url_prefix + options.suffix + location.search,
494
+ url: urlParser(that.info.actions.create.url, that.model),
508
495
  beforeSend: function() {
509
496
  console.log(obj_to_json(that.model));
510
497
  event_hub.$emit('dimmerOn');
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vue_crud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10.8.4
4
+ version: 0.1.10.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donald Chiang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-23 00:00:00.000000000 Z
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,6 +89,7 @@ files:
89
89
  - lib/generators/vue_crud/templates/assets/fonts/fa/fontawesome-webfont.woff2
90
90
  - lib/generators/vue_crud/templates/assets/images/froala_editor/color_picker.png
91
91
  - lib/generators/vue_crud/templates/assets/images/semantic-ui/flags.png
92
+ - lib/generators/vue_crud/templates/assets/javascripts/.DS_Store
92
93
  - lib/generators/vue_crud/templates/assets/javascripts/codemirror.js
93
94
  - lib/generators/vue_crud/templates/assets/javascripts/froala_editor/froala_editor.js
94
95
  - lib/generators/vue_crud/templates/assets/javascripts/froala_editor/languages/en_gb.js