bootbox_crud 0.1.1.4 → 0.1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2151d8412c22e57b5db6843096a39f506488ee2e
4
- data.tar.gz: acf811760e07a07c9412785c43f2ee79b00f4420
3
+ metadata.gz: ec83d2ca42f15ef6aff838d2ee691eba56a354db
4
+ data.tar.gz: 85d6d3a8d032b34b750c50c3655f26cec36141e0
5
5
  SHA512:
6
- metadata.gz: e85e6b4f5dca7a58ff176156ead11422f59ff16134aa5ee9332fa839a3ba20340c585c9e3530a5d74d80ed6d61ee1328fb0690dc546deb906e941e54600f7516
7
- data.tar.gz: 4f55f8e0c2551fb184ffbb51e60cf2b24f588f2f0306140dcab533e4b5233f4f25e994d72aae14151da8835270b6c65d3eabc20fb56e8710361451b6cf9d950b
6
+ metadata.gz: 5cf5f589dc362c27a96ec89921ffbb34e754393d64114171fe4143a3686926e0f3235cfb838571f0658c7dd7dd8c5dc2c42031aeda91887f4f12b48b41d371c1
7
+ data.tar.gz: 8cc9dccba596aa9c57a54ba5485c84c494b8585b9f0961435a82751a58fb39676b5fef00021ec7fc810ccba2fa130912843d34528baa9bb2bcbb098f8e819cd5
@@ -12,5 +12,5 @@ var modal = $('.bootbox.modal');
12
12
  BBCrud.Alert.show('<%= success_alert %>');
13
13
  modal.modal('hide');
14
14
  var path = '<%= defined?(visit_path) ? visit_path : nil %>';
15
- Turbolinks.visit(path === '' ? null : path);
15
+ if (path !== false) Turbolinks.visit(path === '' ? null : path);
16
16
  <%- end %>
@@ -1,5 +1,5 @@
1
1
  module BootboxCrud
2
2
  module Rails
3
- VERSION = "0.1.1.4"
3
+ VERSION = "0.1.1.5"
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ BBCrud.Modals = function () {
4
4
 
5
5
  var modals = {
6
6
  form: function(id, title, btnLabel, url, exec, timeout, timeoutExec, options) {
7
+ options = $.extend({ data: {} }, options);
7
8
  var buttons = {
8
9
  close: {
9
10
  "label" : "Close"
@@ -12,7 +13,7 @@ BBCrud.Modals = function () {
12
13
  "label" : btnLabel,
13
14
  "className" : "btn-success",
14
15
  "callback": function() {
15
- if (options.dontSubmit !== true) {
16
+ if (options.data.bbDontSubmit !== true) {
16
17
  $('.bootbox.modal').find('input[type="submit"]').closest('form').submit();
17
18
  }
18
19
  if (timeoutExec !== null && typeof timeoutExec != 'undefined') { setTimeout(timeoutExec, timeout); }
@@ -20,7 +21,7 @@ BBCrud.Modals = function () {
20
21
  }
21
22
  }
22
23
  };
23
- if (id !== -1 && options.showDeleteBtn !== false) {
24
+ if (id !== -1 && options.data.bbShowDelete !== false) {
24
25
  $.extend(buttons, {
25
26
  delete: {
26
27
  "label" : "Delete",
@@ -33,7 +34,16 @@ BBCrud.Modals = function () {
33
34
  })
34
35
  }
35
36
 
36
- var modal = bootbox.dialog({
37
+ var bbOptions = Object.keys(options.data).reduce(function (result, key) {
38
+ if (key.indexOf('bb') != -1) {
39
+ var cleanKey = key.replace('bb', '');
40
+ cleanKey = cleanKey[0].toLowerCase() + cleanKey.slice(1);
41
+ result[cleanKey] = options.data[key];
42
+ }
43
+ return result;
44
+ }, {});
45
+
46
+ var modal = bootbox.dialog($.extend(bbOptions || {}, {
37
47
  message : "Loading form...",
38
48
  title : title,
39
49
  backdrop : "static",
@@ -41,8 +51,16 @@ BBCrud.Modals = function () {
41
51
  show : true,
42
52
  header : title,
43
53
  buttons: buttons
44
- });
45
- $.get(url, options.data, function(data) {
54
+ }));
55
+
56
+ var reqParams = Object.keys(options.data).reduce(function (result, key) {
57
+ if (key.indexOf('bb') == -1) {
58
+ result[key] = options.data[key];
59
+ }
60
+ return result;
61
+ }, {});
62
+
63
+ $.get(url, reqParams, function(data) {
46
64
  var result = $(data);
47
65
  var content = result.attr('id') === 'content' ? result : result.find('#content');
48
66
  modal.find('.modal-body').html(content);
@@ -62,7 +80,7 @@ BBCrud.Modals = function () {
62
80
  other: function (id, title, baseUrl, actionName, exec, timeout, timeoutExec, data) {
63
81
  if (typeof id === 'object') id = id.id;
64
82
  var url = baseUrl + id + '/' + actionName;
65
- modals.form(id, title, actionName.charAt(0).toUpperCase() + actionName.slice(1), url, exec, timeout, timeoutExec, { baseUrl: baseUrl, data: data, showDeleteBtn: false });
83
+ modals.form(id, title, actionName.charAt(0).toUpperCase() + actionName.slice(1), url, exec, timeout, timeoutExec, { baseUrl: baseUrl, data: $.extend({'bb-show-delete': false}, data) });
66
84
  },
67
85
  delete: function (id, baseUrl, exec) {
68
86
  bootbox.confirm('Are you sure?', function(result) {
@@ -73,16 +91,16 @@ BBCrud.Modals = function () {
73
91
  dataType: 'script',
74
92
  type: 'DELETE'
75
93
  }).success(function () {
76
- if (typeof exec != 'undefined') { exec(); }
77
- BBCrud.Alert.show('Deleted');
78
- }).error(function () {
79
- BBCrud.Alert.show('Something went wrong!');
80
- });
94
+ if (typeof exec != 'undefined') { exec(); }
95
+ BBCrud.Alert.show('Deleted');
96
+ }).error(function () {
97
+ BBCrud.Alert.show('Something went wrong!');
98
+ });
81
99
  }
82
100
  });
83
101
  },
84
- show: function(id, title, baseUrl) {
85
- var modal = bootbox.dialog({
102
+ show: function(id, title, baseUrl, data) {
103
+ var modal = bootbox.dialog($.extend(data.bb, {
86
104
  message : "Loading form...",
87
105
  title : title,
88
106
  backdrop : "static",
@@ -94,17 +112,17 @@ BBCrud.Modals = function () {
94
112
  "label" : "Close"
95
113
  }
96
114
  }
97
- });
98
- $.get(baseUrl + id, function(data) {
99
- handleResponse(data);
115
+ }));
116
+ $.get(baseUrl + id, function(result) {
117
+ handleResponse(result);
100
118
  }).error(function (response) {
101
119
  if (response.status === 200) {
102
120
  handleResponse(response.responseText);
103
121
  }
104
122
  console.log(response);
105
123
  });
106
- function handleResponse(data) {
107
- var result = $(data);
124
+ function handleResponse(response) {
125
+ var result = $(response);
108
126
  var content = result.attr('id') === 'content' ? result : result.find('#content');
109
127
  modal.find('.modal-body').html(content);
110
128
  }
@@ -134,7 +152,7 @@ BBCrud.Models = function () {
134
152
  $.extend(BBCrud[modelName], actions);
135
153
  }
136
154
  }
137
-
155
+
138
156
  var models = {
139
157
  add: function(modelName, url, titleName) {
140
158
  var modelCRUD = function () {
@@ -145,10 +163,10 @@ BBCrud.Models = function () {
145
163
  BBCrud.Modals.create('Create ' + titleName, baseUrl, null, data);
146
164
  },
147
165
  update: function (data) {
148
- BBCrud.Modals.update(data.id, 'Edit ' + titleName, baseUrl);
166
+ BBCrud.Modals.update(data.id, 'Edit ' + titleName, baseUrl, undefined, false, undefined, undefined, data);
149
167
  },
150
168
  show: function (data) {
151
- BBCrud.Modals.show(data.id, titleName.charAt(0).toUpperCase() + titleName.slice(1) + ' detail', baseUrl);
169
+ BBCrud.Modals.show(data.id, titleName.charAt(0).toUpperCase() + titleName.slice(1) + ' detail', baseUrl, data);
152
170
  }
153
171
  };
154
172
  return methods;
@@ -202,5 +220,5 @@ BBCrud.Alert = function() {
202
220
  }();
203
221
 
204
222
  $(function() {
205
- BBCrud.Alert.init({selector: '.bb-alert'});
223
+ BBCrud.Alert.init({selector: '.bb-alert'});
206
224
  });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootbox_crud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.4
4
+ version: 0.1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jiri Kaipr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-24 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties