it-logica-application-backbone 1.1.8 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. data/VERSION +1 -1
  2. data/app/assets/javascripts/backbone_js/bootstrap_modal.js +234 -0
  3. data/app/assets/javascripts/backbone_js/ladas_breadcrumb.js.coffee +15 -2
  4. data/app/assets/javascripts/backbone_js/ladas_editable_table_aligner.js.coffee +243 -0
  5. data/app/assets/javascripts/backbone_js/ladas_editable_table_builder.js.coffee +341 -0
  6. data/app/assets/javascripts/backbone_js/ladas_editable_table_modal_dialog.js.coffee +93 -0
  7. data/app/assets/javascripts/backbone_js/ladas_functions.js +8 -0
  8. data/app/assets/javascripts/backbone_js/ladas_saving.js +6 -0
  9. data/app/assets/javascripts/backbone_js/ladas_table_builder.js.coffee +1 -1
  10. data/app/assets/stylesheets/backbone_css/bootstrap_modal.css +139 -0
  11. data/app/assets/stylesheets/backbone_css/design.css +1 -1
  12. data/app/assets/stylesheets/backbone_css/editable_tables.css.scss +108 -0
  13. data/app/views/helpers/editable_table/_build_ajax_callback_code.html.erb +3 -0
  14. data/app/views/helpers/editable_table/_build_table.html.erb +128 -0
  15. data/app/views/helpers/editable_table/_build_table_data.html.erb +14 -0
  16. data/app/views/helpers/editable_table/_build_table_filter.html.erb +70 -0
  17. data/app/views/helpers/editable_table/_build_table_header.html.erb +136 -0
  18. data/app/views/helpers/editable_table/_build_table_pager.html.erb +31 -0
  19. data/app/views/helpers/editable_table/_build_table_text_description.html.erb +66 -0
  20. data/app/views/helpers/editable_table/_build_table_wrapper.html.erb +106 -0
  21. data/it-logica-application-backbone.gemspec +16 -2
  22. data/lib/model_mixins/table_builder_class_methods.rb +49 -0
  23. data/lib/table_settings/table_action.rb +5 -0
  24. data/lib/table_settings/table_column.rb +11 -0
  25. data/lib/view_mixins/table.rb +5 -0
  26. metadata +29 -15
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.8
1
+ 1.2.0
@@ -0,0 +1,234 @@
1
+ /* =========================================================
2
+ * bootstrap-modal.js v2.2.1
3
+ * http://twitter.github.com/bootstrap/javascript.html#modals
4
+ * =========================================================
5
+ * Copyright 2012 Twitter, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ * ========================================================= */
19
+
20
+
21
+ !function ($) {
22
+
23
+ "use strict"; // jshint ;_;
24
+
25
+
26
+ /* MODAL CLASS DEFINITION
27
+ * ====================== */
28
+
29
+ var Modal = function (element, options) {
30
+ this.options = options
31
+ this.$element = $(element)
32
+ .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
33
+ this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
34
+ }
35
+
36
+ Modal.prototype = {
37
+
38
+ constructor: Modal
39
+
40
+ , toggle: function () {
41
+ return this[!this.isShown ? 'show' : 'hide']()
42
+ }
43
+
44
+ , show: function () {
45
+ var that = this
46
+ , e = $.Event('show')
47
+
48
+ this.$element.trigger(e)
49
+
50
+ if (this.isShown || e.isDefaultPrevented()) return
51
+
52
+ this.isShown = true
53
+
54
+ this.escape()
55
+
56
+ this.backdrop(function () {
57
+ var transition = $.support.transition && that.$element.hasClass('fade')
58
+
59
+ if (!that.$element.parent().length) {
60
+ that.$element.appendTo(document.body) //don't move modals dom position
61
+ }
62
+
63
+ that.$element
64
+ .show()
65
+
66
+ if (transition) {
67
+ that.$element[0].offsetWidth // force reflow
68
+ }
69
+
70
+ that.$element
71
+ .addClass('in')
72
+ .attr('aria-hidden', false)
73
+
74
+ that.enforceFocus()
75
+
76
+ transition ?
77
+ that.$element.one($.support.transition.end, function () { that.$element.focus().trigger('shown') }) :
78
+ that.$element.focus().trigger('shown')
79
+
80
+ })
81
+ }
82
+
83
+ , hide: function (e) {
84
+ e && e.preventDefault()
85
+
86
+ var that = this
87
+
88
+ e = $.Event('hide')
89
+
90
+ this.$element.trigger(e)
91
+
92
+ if (!this.isShown || e.isDefaultPrevented()) return
93
+
94
+ this.isShown = false
95
+
96
+ this.escape()
97
+
98
+ $(document).off('focusin.modal')
99
+
100
+ this.$element
101
+ .removeClass('in')
102
+ .attr('aria-hidden', true)
103
+
104
+ $.support.transition && this.$element.hasClass('fade') ?
105
+ this.hideWithTransition() :
106
+ this.hideModal()
107
+ }
108
+
109
+ , enforceFocus: function () {
110
+ var that = this
111
+ $(document).on('focusin.modal', function (e) {
112
+ if (that.$element[0] !== e.target && !that.$element.has(e.target).length) {
113
+ that.$element.focus()
114
+ }
115
+ })
116
+ }
117
+
118
+ , escape: function () {
119
+ var that = this
120
+ if (this.isShown && this.options.keyboard) {
121
+ this.$element.on('keyup.dismiss.modal', function ( e ) {
122
+ e.which == 27 && that.hide()
123
+ })
124
+ } else if (!this.isShown) {
125
+ this.$element.off('keyup.dismiss.modal')
126
+ }
127
+ }
128
+
129
+ , hideWithTransition: function () {
130
+ var that = this
131
+ , timeout = setTimeout(function () {
132
+ that.$element.off($.support.transition.end)
133
+ that.hideModal()
134
+ }, 500)
135
+
136
+ this.$element.one($.support.transition.end, function () {
137
+ clearTimeout(timeout)
138
+ that.hideModal()
139
+ })
140
+ }
141
+
142
+ , hideModal: function (that) {
143
+ this.$element
144
+ .hide()
145
+ .trigger('hidden')
146
+
147
+ this.backdrop()
148
+ }
149
+
150
+ , removeBackdrop: function () {
151
+ this.$backdrop.remove()
152
+ this.$backdrop = null
153
+ }
154
+
155
+ , backdrop: function (callback) {
156
+ var that = this
157
+ , animate = this.$element.hasClass('fade') ? 'fade' : ''
158
+
159
+ if (this.isShown && this.options.backdrop) {
160
+ var doAnimate = $.support.transition && animate
161
+
162
+ this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
163
+ .appendTo(document.body)
164
+
165
+ this.$backdrop.click(
166
+ this.options.backdrop == 'static' ?
167
+ $.proxy(this.$element[0].focus, this.$element[0])
168
+ : $.proxy(this.hide, this)
169
+ )
170
+
171
+ if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
172
+
173
+ this.$backdrop.addClass('in')
174
+
175
+ doAnimate ?
176
+ this.$backdrop.one($.support.transition.end, callback) :
177
+ callback()
178
+
179
+ } else if (!this.isShown && this.$backdrop) {
180
+ this.$backdrop.removeClass('in')
181
+
182
+ $.support.transition && this.$element.hasClass('fade')?
183
+ this.$backdrop.one($.support.transition.end, $.proxy(this.removeBackdrop, this)) :
184
+ this.removeBackdrop()
185
+
186
+ } else if (callback) {
187
+ callback()
188
+ }
189
+ }
190
+ }
191
+
192
+
193
+ /* MODAL PLUGIN DEFINITION
194
+ * ======================= */
195
+
196
+ $.fn.modal = function (option) {
197
+ return this.each(function () {
198
+ var $this = $(this)
199
+ , data = $this.data('modal')
200
+ , options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option)
201
+ if (!data) $this.data('modal', (data = new Modal(this, options)))
202
+ if (typeof option == 'string') data[option]()
203
+ else if (options.show) data.show()
204
+ })
205
+ }
206
+
207
+ $.fn.modal.defaults = {
208
+ backdrop: true
209
+ , keyboard: true
210
+ , show: true
211
+ }
212
+
213
+ $.fn.modal.Constructor = Modal
214
+
215
+
216
+ /* MODAL DATA-API
217
+ * ============== */
218
+
219
+ $(document).on('click.modal.data-api', '[data-toggle="modal"]', function (e) {
220
+ var $this = $(this)
221
+ , href = $this.attr('href')
222
+ , $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7
223
+ , option = $target.data('modal') ? 'toggle' : $.extend({ remote:!/#/.test(href) && href }, $target.data(), $this.data())
224
+
225
+ e.preventDefault()
226
+
227
+ $target
228
+ .modal(option)
229
+ .one('hide', function () {
230
+ $this.focus()
231
+ })
232
+ })
233
+
234
+ }(window.jQuery);
@@ -22,7 +22,7 @@ class Breadcrumbs
22
22
  title_suffix = Breadcrumbs.load_title_suffix(title_suffix)
23
23
 
24
24
 
25
- $('a[data-breadcrumb-id],li[data-breadcrumb-id]').each (index, element) =>
25
+ $('a[data-breadcrumb-id],li[data-breadcrumb-id],a[data-tree-breadcrumb-id],li[data-tree-breadcrumb-id]').each (index, element) =>
26
26
  $(element).removeClass('active')
27
27
 
28
28
  array_of_breadcrubm_texts = Array()
@@ -67,11 +67,24 @@ class Breadcrumbs
67
67
  else
68
68
  found.addClass('active')
69
69
 
70
- @make_finding_string: (val) ->
70
+ # and for one level menus
71
+ finding_string = Breadcrumbs.make_finding_string_for_one_lvl_menu(val)
72
+ #console.log $(finding_string)
73
+ found = $(finding_string)
74
+ if found
75
+ found.addClass('active')
76
+
77
+
78
+ @make_finding_string_for_one_lvl_menu: (val) ->
71
79
  finding_string = "li[data-breadcrumb-id='" + val + "']"
72
80
  finding_string += ",a[data-breadcrumb-id='" + val + "']"
73
81
  return finding_string
74
82
 
83
+ @make_finding_string: (val) ->
84
+ finding_string = "li[data-tree-breadcrumb-id='" + val + "']"
85
+ finding_string += ",a[data-tree-breadcrumb-id='" + val + "']"
86
+ return finding_string
87
+
75
88
  @change_document_title: (title_prefix,suffix, val) ->
76
89
  $(document).attr('title', title_prefix + val + suffix);
77
90
 
@@ -0,0 +1,243 @@
1
+ class EditableTableAligner
2
+ @align_table: (obj, xhr) ->
3
+ # move colhead class to left column
4
+ EditableTableAligner.align_static_left_columns(obj, xhr)
5
+ console.log("left columns moved")
6
+
7
+
8
+ # allowing of paired scrolling
9
+ EditableTableAligner.paired_left_right_scrolling(obj)
10
+ console.log("left right scrolling paired")
11
+ EditableTableAligner.paired_up_down_scrolling(obj)
12
+ console.log("up down scrolling paired")
13
+
14
+
15
+ # align widths and heights at last after moving all columns
16
+ # align withs of header and body of table
17
+ EditableTableAligner.align_widths(obj)
18
+ console.log("align widths")
19
+
20
+
21
+ # aligning heights of static left or right columns and center content of table
22
+ EditableTableAligner.align_heights(obj)
23
+ console.log("align heights")
24
+
25
+ @align_after_rows_update: (obj) ->
26
+ # move colhead class to left column
27
+ EditableTableAligner.align_static_left_columns_after_row_update(obj)
28
+ console.log("left columns moved")
29
+
30
+ # align widths and heights at last after moving all columns
31
+ # align withs of header and body of table
32
+ EditableTableAligner.align_widths(obj)
33
+ console.log("roew align widths")
34
+ # aligning heights of static left or right columns and center content of table
35
+ EditableTableAligner.align_heights(obj)
36
+ console.log("roew align heights")
37
+
38
+ #########################
39
+ ### private methods #########
40
+ ##############################
41
+
42
+ @align_widths: (obj) ->
43
+ # going trough headers th
44
+ # console.log($("#" + obj.form_id).find('td[data-width-align-id]'))
45
+
46
+ $("#" + obj.form_id).find('th[data-width-align-id]').each (index, element) =>
47
+
48
+ # loading paired td and th
49
+ th = $(element)
50
+
51
+ # id of paired th and td elements
52
+ width_align_id = th.data("width-align-id")
53
+
54
+ td = $("#" + obj.form_id).find('td[data-width-align-id="' + width_align_id + '"]').first()
55
+
56
+ #careful delete one by one, or scrolling will be lost
57
+ # have to delete it from elements, otherwise the width would increase (alwazs adding padding nad vbroder to outerWidth)
58
+ th.css({
59
+ 'min-width': "",
60
+ 'max-width': ""
61
+ })
62
+
63
+ td.css({
64
+ 'min-width': "",
65
+ 'max-width': ""
66
+ })
67
+
68
+
69
+ # determining max width
70
+ th_width = th.outerWidth()
71
+ td_width = td.outerWidth()
72
+
73
+
74
+ if th_width > td_width
75
+ max_width = th_width
76
+ else
77
+ max_width = td_width
78
+
79
+
80
+ # setting max width
81
+ th.css({
82
+ 'min-width': max_width,
83
+ 'max-width': max_width
84
+ })
85
+
86
+ td.css({
87
+ 'min-width': max_width,
88
+ 'max-width': max_width
89
+ })
90
+
91
+
92
+ return
93
+
94
+ @paired_left_right_scrolling: (obj) ->
95
+ #scrolling of head must affect body and vice versa
96
+ head = $("#" + obj.form_id).find(".centerContainer .scrollTargetContainter").first()
97
+ body = $("#" + obj.form_id).find(".centerContainer .detachedTableContainer").first()
98
+
99
+ EditableTableAligner.side_scroll(head, body)
100
+ EditableTableAligner.side_scroll(body, head)
101
+
102
+
103
+ @side_scroll: (source, target) ->
104
+ $(source).scroll ->
105
+ target.scrollLeft(parseInt(source.scrollLeft()))
106
+
107
+
108
+
109
+ @paired_up_down_scrolling: (obj) ->
110
+ #scrolling of head must affect body and vice versa
111
+ center_body = $("#" + obj.form_id).find(".centerContainer .detachedTableContainer").first()
112
+ fixed_left_column_body = $("#" + obj.form_id).find(".fixedLeftColumn .detachedTableContainer").first()
113
+
114
+
115
+ EditableTableAligner.scroll(center_body, fixed_left_column_body)
116
+ EditableTableAligner.scroll(fixed_left_column_body, center_body)
117
+
118
+ @scroll: (source, target) ->
119
+ $(source).scroll ->
120
+ target.scrollTop(parseInt(source.scrollTop()))
121
+
122
+
123
+ @align_static_left_columns: (obj, xhr) ->
124
+ orig_head = $("#" + obj.form_id).find('.centerContainer .scrollTargetContainter')
125
+ head = $("#" + obj.form_id).find(".fixedLeftColumn .table_head thead")
126
+ # first clear the head, but only if not by XHR, head is not sent by ajax
127
+
128
+ console.log(xhr)
129
+ if xhr? && !xhr
130
+ head.html("")
131
+ # then fill it with actual data
132
+ orig_head.find("thead tr").each (index, element) =>
133
+ EditableTableAligner.move_cell_to_static_column(element, head)
134
+
135
+ # can delete orid headcols when I duplicated them, otherwise the height info is wrong
136
+ #$(orig_head).find(".headcol").remove()
137
+
138
+
139
+ orig_body = $("#" + obj.form_id).find('.centerContainer .detachedTableContainer')
140
+ body = $("#" + obj.form_id).find(".fixedLeftColumn .table_body tbody")
141
+ # first clear the body
142
+ body.html("")
143
+ # then fill it with actual data
144
+ orig_body.find("tr").each (index, element) =>
145
+ EditableTableAligner.move_cell_to_static_column(element, body)
146
+
147
+ # can delete orid headcols when I duplicated them, otherwise the height info is wrong
148
+ #$(orig_body).find(".headcol").remove()
149
+
150
+ @align_heights: (obj) ->
151
+ ##################### !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
152
+ ###################### omezim je na thead, tbody bude mit fixni vysku sloupcu, prepocinani s 500 radky, trva strasne dlouho
153
+ #$("#" + obj.form_id).find('.fixedLeftColumn tr').each (index, element) =>
154
+
155
+ $("#" + obj.form_id).find('.fixedLeftColumn thead tr').each (index, element) =>
156
+
157
+ # loading paired tr of left column and right
158
+ tr_left = $(element)
159
+
160
+ # id of paired th and td elements
161
+ height_align_id = tr_left.data("row-count-number")
162
+
163
+ tr_center = $("#" + obj.form_id).find('.centerContainer tr[data-row-count-number="' + height_align_id + '"]').first()
164
+
165
+ # carefull delete of height line by line, or scrolling will be lost
166
+ # have to delete it from headers first, as it is not sent by ajax, othewwise it will increase with each ajax reload
167
+ tr_left.css({
168
+ 'height': "",
169
+ })
170
+ tr_center.css({
171
+ 'height': "",
172
+ })
173
+
174
+ # determining max width
175
+ td_left_height = tr_left.outerHeight()
176
+ td_center_height = tr_center.outerHeight()
177
+
178
+ if td_left_height > td_center_height
179
+ max_height = td_left_height
180
+ else
181
+ max_height = td_center_height
182
+
183
+
184
+ # setting max width
185
+ tr_left.css({
186
+ 'height': max_height,
187
+ })
188
+
189
+ tr_center.css({
190
+ 'height': max_height,
191
+ })
192
+
193
+ @move_cell_to_static_column: (element, body) ->
194
+ tr_element = $(element).clone()
195
+ tr_element.html("")
196
+
197
+
198
+ $(element).find('.headcol').each (i, e) =>
199
+ orig_element = $(e)
200
+
201
+ tr_element.append(orig_element)
202
+
203
+ # remove it from old table
204
+ #$(orig_element).remove()
205
+
206
+ body.append(tr_element)
207
+
208
+
209
+ @align_static_left_columns_after_row_update: (obj) ->
210
+ orig_body = $("#" + obj.form_id).find('.centerContainer .detachedTableContainer')
211
+
212
+ # going trough all tr, and then filtering nlz by those who has head col, that means they were updated
213
+ #orig_body.find("tr").each (index, element) =>
214
+ # noooo going through only updated tr
215
+ for row in EditableTableBuilder.obj.data
216
+ do (row) ->
217
+ element = $("#" + obj.form_id).find('.centerContainer tr[data-row-id="' + row.row_id + '"]')
218
+ # finding destination row from orig row
219
+ destination_row_id = $(element).data("row-count-number")
220
+ destination_row = $("#" + obj.form_id).find('.fixedLeftColumn tr[data-row-count-number="' + destination_row_id + '"]')
221
+
222
+
223
+ EditableTableAligner.move_cells_to_static_rows(element, destination_row)
224
+
225
+ @move_cells_to_static_rows: (element, destination_row) ->
226
+ if $(element).find('.headcol').length > 0
227
+ # first clear the row before updating row
228
+ destination_row.html("")
229
+
230
+ $(element).find('.headcol').each (i, e) =>
231
+ orig_element = $(e)
232
+
233
+ destination_row.append(orig_element)
234
+
235
+ # have copy colors of the center table to left column
236
+ $(destination_row).attr("style", $(element).attr("style"))
237
+
238
+ window.EditableTableAligner = EditableTableAligner
239
+
240
+
241
+
242
+
243
+