bhf 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -74,7 +74,7 @@ class Bhf::EntriesController < Bhf::ApplicationController
74
74
  def object_to_bhf_display_hash
75
75
  @platform.columns.each_with_object({to_bhf_s: @object.to_bhf_s}) do |column, hash|
76
76
  unless column.field.macro == :column && @object.send(column.name).blank?
77
- p = "bhf/pages/macro/#{column.field.macro}/#{column.field.display_type}"
77
+ p = "bhf/pages/macro/#{column.field.macro}/#{column.field.display_type}.html"
78
78
  hash[column.name] = render_to_string partial: p, locals: {column: column, object: @object}
79
79
  end
80
80
  end
@@ -1,2 +1,2 @@
1
1
  = node f, field do
2
- = f.text_field field.name, class: "picker #{field.type}", value: f.object.send(field.name) ? l(f.object.send(field.name), format: '%Y-%m-%d %H:%M') : nil
2
+ = f.text_field field.name, class: "picker #{field.type}", value: f.object.send(field.name) ? l(f.object.send(field.name), format: t("bhf.helpers.input.date_format.#{field.type}")) : nil
@@ -1,5 +1,5 @@
1
1
  - platform.pagination.template = self
2
- %table{id: "#{platform.name}_platform", class: (platform.custom_columns? ? :custom_columns : :default_columns)}
2
+ %table.data_table{id: "#{platform.name}_platform", class: (platform.custom_columns? ? :custom_columns : :default_columns)}
3
3
  %caption
4
4
  %h4= platform.title
5
5
  %p.info= platform.pagination.info platform
@@ -33,7 +33,13 @@ en:
33
33
  file:
34
34
  delete: Delete file
35
35
  reselect: Please reselect the file
36
-
36
+ input:
37
+ date_format:
38
+ timestamp: '%Y-%m-%d %H:%M'
39
+ datetime: '%Y-%m-%d %H:%M'
40
+ date: '%Y-%m-%d'
41
+ time: '%H:%M'
42
+
37
43
  quick_edit:
38
44
  buttons:
39
45
  cancel: Cancel
@@ -26,32 +26,18 @@ window.addEvent('domready', function(){
26
26
  new ArrayFields(elem);
27
27
  });
28
28
 
29
- var dateFormat = Locale.get('Date.shortDate').replace(/%/g, '');
30
- var timeFormat = 'H:i'; // Locale.get('Date.shortTime').replace(/%/g, '')
31
- var dateMonths = Locale.get('Date.months');
32
- var dateDays = Locale.get('Date.days');
33
- new DatePicker(scope.getElements('.picker.datetime, .picker.timestamp'), {
34
- allowEmpty: true,
35
- inputOutputFormat: 'Y-m-d H:i',
36
- months: dateMonths,
37
- days: dateDays,
29
+ // TODO: i18n datepicker
30
+ new Picker.Date(scope.getElements('.picker.datetime, .picker.timestamp'), {
38
31
  timePicker: true,
39
- format: dateFormat+' '+timeFormat
32
+ format: '%Y-%m-%d %H:%M'
40
33
  });
41
- new DatePicker(scope.getElements('.picker.date'), {
42
- allowEmpty: true,
43
- inputOutputFormat: 'Y-m-d H:i',
44
- months: dateMonths,
45
- days: dateDays,
46
- format: dateFormat
34
+ new Picker.Date(scope.getElements('.picker.date'), {
35
+ timePicker: false,
36
+ format: '%Y-%m-%d'
47
37
  });
48
- new DatePicker(scope.getElements('.picker.time'), {
49
- allowEmpty: true,
50
- inputOutputFormat: 'Y-m-d H:i',
51
- months: dateMonths,
52
- days: dateDays,
53
- timePickerOnly: true,
54
- format: timeFormat
38
+ new Picker.Date(scope.getElements('.picker.time'), {
39
+ pickOnly: 'time',
40
+ format: '%H:%M'
55
41
  });
56
42
  };
57
43
 
@@ -0,0 +1,16 @@
1
+ /*
2
+ ---
3
+ name: Locale.de-DE.DatePicker
4
+ description: German Language File for DatePicker
5
+ authors: Bastian Bringenberg
6
+ requires: [More/Locale]
7
+ provides: Locale.de-DE.DatePicker
8
+ ...
9
+ */
10
+
11
+
12
+ Locale.define('de-DE', 'DatePicker', {
13
+ select_a_time: 'Wähle eine Zeit',
14
+ use_mouse_wheel: 'Mit dem Mausrad kannst du schneller die Werte ändern',
15
+ time_confirm_button: 'OK'
16
+ });
@@ -0,0 +1,19 @@
1
+ /*
2
+ ---
3
+ name: Locale.en-US.DatePicker
4
+ description: English Language File for DatePicker
5
+ authors: Arian Stolwijk
6
+ requires: [More/Locale]
7
+ provides: Locale.en-US.DatePicker
8
+ ...
9
+ */
10
+
11
+
12
+ Locale.define('en-US', 'DatePicker', {
13
+ select_a_time: 'Select a time',
14
+ use_mouse_wheel: 'Use the mouse wheel to quickly change value',
15
+ time_confirm_button: 'OK',
16
+ apply_range: 'Apply',
17
+ cancel: 'Cancel',
18
+ week: 'Wk'
19
+ });
@@ -0,0 +1,344 @@
1
+ /*
2
+ ---
3
+ name: Picker
4
+ description: Creates a Picker, which can be used for anything
5
+ authors: Arian Stolwijk
6
+ requires: [Core/Element.Dimensions, Core/Fx.Tween, Core/Fx.Transitions]
7
+ provides: Picker
8
+ ...
9
+ */
10
+
11
+
12
+ var Picker = new Class({
13
+
14
+ Implements: [Options, Events],
15
+
16
+ options: {/*
17
+ onShow: function(){},
18
+ onOpen: function(){},
19
+ onHide: function(){},
20
+ onClose: function(){},*/
21
+
22
+ pickerClass: 'datepicker',
23
+ inject: null,
24
+ animationDuration: 400,
25
+ useFadeInOut: true,
26
+ positionOffset: {x: 0, y: 0},
27
+ pickerPosition: 'bottom',
28
+ draggable: true,
29
+ showOnInit: true,
30
+ columns: 1,
31
+ footer: false
32
+ },
33
+
34
+ initialize: function(options){
35
+ this.setOptions(options);
36
+ this.constructPicker();
37
+ if (this.options.showOnInit) this.show();
38
+ },
39
+
40
+ constructPicker: function(){
41
+ var options = this.options;
42
+
43
+ var picker = this.picker = new Element('div', {
44
+ 'class': options.pickerClass,
45
+ styles: {
46
+ left: 0,
47
+ top: 0,
48
+ display: 'none',
49
+ opacity: 0
50
+ }
51
+ }).inject(options.inject || document.body);
52
+ picker.addClass('column_' + options.columns);
53
+
54
+ if (options.useFadeInOut){
55
+ picker.set('tween', {
56
+ duration: options.animationDuration,
57
+ link: 'cancel'
58
+ });
59
+ }
60
+
61
+ // Build the header
62
+ var header = this.header = new Element('div.header').inject(picker);
63
+
64
+ var title = this.title = new Element('div.title').inject(header);
65
+ var titleID = this.titleID = 'pickertitle-' + String.uniqueID();
66
+ this.titleText = new Element('div', {
67
+ 'role': 'heading',
68
+ 'class': 'titleText',
69
+ 'id': titleID,
70
+ 'aria-live': 'assertive',
71
+ 'aria-atomic': 'true'
72
+ }).inject(title);
73
+
74
+ this.closeButton = new Element('div.closeButton[text=x][role=button]')
75
+ .addEvent('click', this.close.pass(false, this))
76
+ .inject(header);
77
+
78
+ // Build the body of the picker
79
+ var body = this.body = new Element('div.body').inject(picker);
80
+
81
+ if (options.footer){
82
+ this.footer = new Element('div.footer').inject(picker);
83
+ picker.addClass('footer');
84
+ }
85
+
86
+ // oldContents and newContents are used to slide from the old content to a new one.
87
+ var slider = this.slider = new Element('div.slider', {
88
+ styles: {
89
+ position: 'absolute',
90
+ top: 0,
91
+ left: 0
92
+ }
93
+ }).set('tween', {
94
+ duration: options.animationDuration,
95
+ transition: Fx.Transitions.Quad.easeInOut
96
+ }).inject(body);
97
+
98
+ this.newContents = new Element('div', {
99
+ styles: {
100
+ position: 'absolute',
101
+ top: 0,
102
+ left: 0
103
+ }
104
+ }).inject(slider);
105
+
106
+ this.oldContents = new Element('div', {
107
+ styles: {
108
+ position: 'absolute',
109
+ top: 0
110
+ }
111
+ }).inject(slider);
112
+
113
+ this.originalColumns = options.columns;
114
+ this.setColumns(options.columns);
115
+
116
+ // IFrameShim for select fields in IE
117
+ var shim = this.shim = window['IframeShim'] ? new IframeShim(picker) : null;
118
+
119
+ // Dragging
120
+ if (options.draggable && typeOf(picker.makeDraggable) == 'function'){
121
+ this.dragger = picker.makeDraggable(shim ? {
122
+ onDrag: shim.position.bind(shim)
123
+ } : null);
124
+ picker.setStyle('cursor', 'move');
125
+ }
126
+ },
127
+
128
+ open: function(noFx){
129
+ if (this.opened == true) return this;
130
+ this.opened = true;
131
+ var self = this,
132
+ picker = this.picker.setStyle('display', 'block').set('aria-hidden', 'false')
133
+ if (this.shim) this.shim.show();
134
+ this.fireEvent('open');
135
+ if (this.options.useFadeInOut && !noFx){
136
+ picker.get('tween').start('opacity', 1).chain(function(){
137
+ self.fireEvent('show');
138
+ this.callChain();
139
+ });
140
+ } else {
141
+ picker.setStyle('opacity', 1);
142
+ this.fireEvent('show');
143
+ }
144
+ return this;
145
+ },
146
+
147
+ show: function(){
148
+ return this.open(true);
149
+ },
150
+
151
+ close: function(noFx){
152
+ if (this.opened == false) return this;
153
+ this.opened = false;
154
+ this.fireEvent('close');
155
+ var self = this, picker = this.picker, hide = function(){
156
+ picker.setStyle('display', 'none').set('aria-hidden', 'true');
157
+ if (self.shim) self.shim.hide();
158
+ self.fireEvent('hide');
159
+ };
160
+ if (this.options.useFadeInOut && !noFx){
161
+ picker.get('tween').start('opacity', 0).chain(hide);
162
+ } else {
163
+ picker.setStyle('opacity', 0);
164
+ hide();
165
+ }
166
+ return this;
167
+ },
168
+
169
+ hide: function(){
170
+ return this.close(true);
171
+ },
172
+
173
+ toggle: function(){
174
+ return this[this.opened == true ? 'close' : 'open']();
175
+ },
176
+
177
+ destroy: function(){
178
+ this.picker.destroy();
179
+ if (this.shim) this.shim.destroy();
180
+ },
181
+
182
+ position: function(x, y){
183
+ var offset = this.options.positionOffset,
184
+ scroll = document.getScroll(),
185
+ size = document.getSize(),
186
+ pickersize = this.picker.getSize();
187
+
188
+ if (typeOf(x) == 'element'){
189
+ var element = x,
190
+ where = y || this.options.pickerPosition;
191
+
192
+ var elementCoords = element.getCoordinates();
193
+
194
+ x = (where == 'left') ? elementCoords.left - pickersize.x
195
+ : (where == 'bottom' || where == 'top') ? elementCoords.left
196
+ : elementCoords.right
197
+ y = (where == 'bottom') ? elementCoords.bottom
198
+ : (where == 'top') ? elementCoords.top - pickersize.y
199
+ : elementCoords.top;
200
+ }
201
+
202
+ x += offset.x * ((where && where == 'left') ? -1 : 1);
203
+ y += offset.y * ((where && where == 'top') ? -1: 1);
204
+
205
+ if ((x + pickersize.x) > (size.x + scroll.x)) x = (size.x + scroll.x) - pickersize.x;
206
+ if ((y + pickersize.y) > (size.y + scroll.y)) y = (size.y + scroll.y) - pickersize.y;
207
+ if (x < 0) x = 0;
208
+ if (y < 0) y = 0;
209
+
210
+ this.picker.setStyles({
211
+ left: x,
212
+ top: y
213
+ });
214
+ if (this.shim) this.shim.position();
215
+ return this;
216
+ },
217
+
218
+ setBodySize: function(){
219
+ var bodysize = this.bodysize = this.body.getSize();
220
+
221
+ this.slider.setStyles({
222
+ width: 2 * bodysize.x,
223
+ height: bodysize.y
224
+ });
225
+ this.oldContents.setStyles({
226
+ left: bodysize.x,
227
+ width: bodysize.x,
228
+ height: bodysize.y
229
+ });
230
+ this.newContents.setStyles({
231
+ width: bodysize.x,
232
+ height: bodysize.y
233
+ });
234
+ },
235
+
236
+ setColumnContent: function(column, content){
237
+ var columnElement = this.columns[column];
238
+ if (!columnElement) return this;
239
+
240
+ var type = typeOf(content);
241
+ if (['string', 'number'].contains(type)) columnElement.set('text', content);
242
+ else columnElement.empty().adopt(content);
243
+
244
+ return this;
245
+ },
246
+
247
+ setColumnsContent: function(content, fx){
248
+ var old = this.columns;
249
+ this.columns = this.newColumns;
250
+ this.newColumns = old;
251
+
252
+ content.forEach(function(_content, i){
253
+ this.setColumnContent(i, _content);
254
+ }, this);
255
+ return this.setContent(null, fx);
256
+ },
257
+
258
+ setColumns: function(columns){
259
+ var _columns = this.columns = new Elements, _newColumns = this.newColumns = new Elements;
260
+ for (var i = columns; i--;){
261
+ _columns.push(new Element('div.column').addClass('column_' + (columns - i)));
262
+ _newColumns.push(new Element('div.column').addClass('column_' + (columns - i)));
263
+ }
264
+
265
+ var oldClass = 'column_' + this.options.columns, newClass = 'column_' + columns;
266
+ this.picker.removeClass(oldClass).addClass(newClass);
267
+
268
+ this.options.columns = columns;
269
+ return this;
270
+ },
271
+
272
+ setContent: function(content, fx){
273
+ if (content) return this.setColumnsContent([content], fx);
274
+
275
+ // swap contents so we can fill the newContents again and animate
276
+ var old = this.oldContents;
277
+ this.oldContents = this.newContents;
278
+ this.newContents = old;
279
+ this.newContents.empty();
280
+
281
+ this.newContents.adopt(this.columns);
282
+
283
+ this.setBodySize();
284
+
285
+ if (fx){
286
+ this.fx(fx);
287
+ } else {
288
+ this.slider.setStyle('left', 0);
289
+ this.oldContents.setStyles({left: 0, opacity: 0});
290
+ this.newContents.setStyles({left: 0, opacity: 1});
291
+ }
292
+ return this;
293
+ },
294
+
295
+ fx: function(fx){
296
+ var oldContents = this.oldContents,
297
+ newContents = this.newContents,
298
+ slider = this.slider,
299
+ bodysize = this.bodysize;
300
+ if (fx == 'right'){
301
+ oldContents.setStyles({left: 0, opacity: 1});
302
+ newContents.setStyles({left: bodysize.x, opacity: 1});
303
+ slider.setStyle('left', 0).tween('left', 0, -bodysize.x);
304
+ } else if (fx == 'left'){
305
+ oldContents.setStyles({left: bodysize.x, opacity: 1});
306
+ newContents.setStyles({left: 0, opacity: 1});
307
+ slider.setStyle('left', -bodysize.x).tween('left', -bodysize.x, 0);
308
+ } else if (fx == 'fade'){
309
+ slider.setStyle('left', 0);
310
+ oldContents.setStyle('left', 0).set('tween', {
311
+ duration: this.options.animationDuration / 2
312
+ }).tween('opacity', 1, 0).get('tween').chain(function(){
313
+ oldContents.setStyle('left', bodysize.x);
314
+ });
315
+ newContents.setStyles({opacity: 0, left: 0}).set('tween', {
316
+ duration: this.options.animationDuration
317
+ }).tween('opacity', 0, 1);
318
+ }
319
+ },
320
+
321
+ toElement: function(){
322
+ return this.picker;
323
+ },
324
+
325
+ setTitle: function(content, fn){
326
+ if (!fn) fn = Function.from;
327
+ this.titleText.empty().adopt(
328
+ Array.from(content).map(function(item, i){
329
+ return typeOf(item) == 'element'
330
+ ? item
331
+ : new Element('div.column', {text: fn(item, this.options)}).addClass('column_' + (i + 1));
332
+ }, this)
333
+ );
334
+ return this;
335
+ },
336
+
337
+ setTitleEvent: function(fn){
338
+ this.titleText.removeEvents('click');
339
+ if (fn) this.titleText.addEvent('click', fn);
340
+ this.titleText.setStyle('cursor', fn ? 'pointer' : '');
341
+ return this;
342
+ }
343
+
344
+ });