backboneAX 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '~> 3.2.1'
4
+
5
+ # Specify your gem's dependencies in backboneAX.gemspec
6
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "backboneAX/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "backboneAX"
7
+ s.version = Backboneax::VERSION
8
+ s.authors = ["Chris Douglas"]
9
+ s.email = ["dougo.chris@gmail.com"]
10
+ s.homepage = "https://github.com/dougochris/backboneAX"
11
+ s.summary = %q{backbone Application Extensions}
12
+ s.description = %q{backbone Application Extensions for cleaner application development}
13
+
14
+ s.rubyforge_project = "backboneAX"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,213 @@
1
+ module BackboneAX
2
+ module BootstrapView
3
+
4
+ def bx_breadcrumbs(links, button = nil)
5
+ content_tag(:ul, '', {class: 'breadcrumb'}) do
6
+ out = []
7
+ links.each_with_index do |value, index|
8
+ if index < links.length - 1
9
+ out << content_tag(:li) do
10
+ safe_join [content_tag(:a, value[1], {id: value[0]}), content_tag(:span, '/', {class: 'divider'})]
11
+ end
12
+ else
13
+ out << content_tag(:li, value[1])
14
+ end
15
+ end
16
+
17
+ unless button.nil?
18
+ out << content_tag(:a, button[:title], button.except(:title).reverse_merge({class: ['btn', 'btn-success']}))
19
+ end
20
+
21
+ out << content_tag(:div, '', {class: 'clear'})
22
+
23
+ safe_join out
24
+ end
25
+ end
26
+
27
+ #FORMS
28
+
29
+ def bx_form_horontal(title = nil, form_id = nil, &block)
30
+ capture_haml do
31
+ haml_tag(:form, {class: 'form-horizontal', id: form_id}) do
32
+ haml_tag(:fieldset) do
33
+ haml_tag(:legend, title) unless title.nil?
34
+ yield() if block_given?
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def bx_form_inline(title = nil, form_id = nil, &block)
41
+ capture_haml do
42
+ haml_tag(:form, {class: 'form-inline', id: form_id}) do
43
+ haml_tag(:fieldset) do
44
+ haml_tag(:legend, title) unless title.nil?
45
+ yield() if block_given?
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ #FIELDS
52
+
53
+ def bx_field_hidden(field_id)
54
+ capture_haml do
55
+ haml_tag(:div, {class: 'hide'}) do
56
+ haml_tag(:input, {type: 'hidden', id: field_id})
57
+ end
58
+ end
59
+ end
60
+
61
+ def bx_field_text(field_id, options = {})
62
+ capture_haml do
63
+ haml_tag(:input, options.slice(:class).merge({id: field_id}))
64
+ end
65
+ end
66
+
67
+ def bx_field_textarea(field_id, options = {})
68
+ capture_haml do
69
+ haml_tag(:textarea, options.slice(:class, :rows).merge({id: field_id}))
70
+ end
71
+ end
72
+
73
+ def bx_field_file(field_id, options = {})
74
+ capture_haml do
75
+ haml_tag(:input, options.slice(:class, :rows).merge({id: field_id, type: 'file'}))
76
+ end
77
+ end
78
+
79
+ def bx_field_select(field_id, items ={}, options = {})
80
+ capture_haml do
81
+ haml_tag(:select, options.slice(:class, :multiple).merge({id: field_id})) do
82
+ items.each do |key, value|
83
+ haml_tag(:option, value, {value: key})
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ def bx_field_switch(label, field_id, options = {})
90
+ capture_haml do
91
+ haml_tag(:div, options.merge({class: 'switch', id: field_id})) do
92
+ haml_tag(:div, {class: 'cb-enable'}) do
93
+ haml_tag(:span, 'On')
94
+ end
95
+ haml_tag(:div, {class: 'cb-disable'}) do
96
+ haml_tag(:span, 'Off')
97
+ end
98
+ haml_tag(:input, options.merge({class: 'hide', type: 'checkbox', id: field_id}))
99
+ end
100
+ end
101
+ end
102
+
103
+ #BUTTONS
104
+ def bx_btn(title, field_id, options = {})
105
+ capture_haml do
106
+ haml_tag(:a, {class: ['btn', options[:class]], id: field_id}) do
107
+ haml_tag(:i, '', {class: options[:icon]}) if options[:icon]
108
+ haml_concat(title)
109
+ end
110
+ end
111
+ end
112
+
113
+ def bx_btn_primary(title, field_id, options = {})
114
+ bx_btn(title, field_id, options.merge(class: 'btn-primary'))
115
+ end
116
+
117
+ def bx_btn_info(title, field_id, options = {})
118
+ bx_btn(title, field_id, options.merge(class: 'btn-info'))
119
+ end
120
+
121
+ def bx_btn_success(title, field_id, options = {})
122
+ bx_btn(title, field_id, options.merge(class: 'btn-success'))
123
+ end
124
+
125
+ def bx_btn_warning(title, field_id, options = {})
126
+ bx_btn(title, field_id, options.merge(class: 'btn-warning'))
127
+ end
128
+
129
+ def bx_btn_danger(title, field_id, options = {})
130
+ bx_btn(title, field_id, options.merge(class: 'btn-danger'))
131
+ end
132
+
133
+ def bx_btn_cancel(field_id = :cancel)
134
+ bx_btn('Cancel', field_id)
135
+ end
136
+
137
+ def bx_btn_save(field_id = :save)
138
+ bx_btn('Cancel', field_id, {class: 'btn-primary'})
139
+ end
140
+
141
+ def bx_btn_dropdown(title, options = {}, &block)
142
+ capture_haml do
143
+ haml_tag(:div, {class: 'btn-group'}) do
144
+ haml_tag(:a, {class: ['btn', 'dropdown-toggle', options[:class]], 'data-toggle' => 'dropdown'}) do
145
+ haml_tag(:i, '', {class: options[:icon]}) if options[:icon]
146
+ haml_concat(title)
147
+ haml_tag(:span, '', {class: :caret})
148
+ end
149
+ haml_tag(:ul, {class: 'dropdown-menu'}) do
150
+ yield if block_given?
151
+ end
152
+ end
153
+ end
154
+ end
155
+
156
+ #CONTROL_GROUP_FIELDS
157
+ def bx_cg_text(label, field_id, options = {})
158
+ bx_cg_group(label, field_id, options) do
159
+ haml_tag(:input, options.slice(:class).merge({id: field_id}))
160
+ end
161
+ end
162
+
163
+ def bx_cg_textarea(label, field_id, options = {})
164
+ bx_cg_group(label, field_id, options) do
165
+ haml_tag(:textarea, options.slice(:class, :rows).merge({id: field_id}))
166
+ end
167
+ end
168
+
169
+ def bx_cg_file(label, field_id, options = {})
170
+ bx_cg_group(label, field_id, options) do
171
+ haml_tag(:input, options.slice(:class, :rows).merge({id: field_id, type: 'file'}))
172
+ end
173
+ end
174
+
175
+ def bx_cg_select(label, field_id, items ={}, options = {})
176
+ bx_cg_group(label, field_id, options) do
177
+ haml_tag(:select, options.slice(:class, :multiple).merge({id: field_id})) do
178
+ items.each do |key, value|
179
+ haml_tag(:option, value, {value: key})
180
+ end
181
+ end
182
+ end
183
+ end
184
+
185
+ def bx_cg_switch(label, field_id, options = {})
186
+ bx_cg_group(label, field_id, options) do
187
+ haml_tag(:div, options.merge({class: 'switch', id: field_id})) do
188
+ haml_tag(:div, {class: 'cb-enable'}) do
189
+ haml_tag(:span, 'On')
190
+ end
191
+ haml_tag(:div, {class: 'cb-disable'}) do
192
+ haml_tag(:span, 'Off')
193
+ end
194
+ haml_tag(:input, options.merge({class: 'hide', type: 'checkbox', id: field_id}))
195
+ end
196
+ end
197
+ end
198
+
199
+ protected
200
+ def bx_cg_group(label, field_id, options = {}, &block)
201
+ capture_haml do
202
+ haml_tag(:div, {class: 'control-group'}) do
203
+ haml_tag(:label, label, {class: 'control-label', for: field_id})
204
+ haml_tag(:div, {class: 'controls'}) do
205
+ yield() if block_given?
206
+ haml_tag(:span, options[:help], {class: 'help-inline'}) unless options[:help].blank?
207
+ end
208
+ end
209
+ end
210
+ end
211
+
212
+ end
213
+ end
@@ -0,0 +1,4 @@
1
+ module BackboneAX
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Backboneax
2
+ VERSION = "0.0.1"
3
+ end
data/lib/backboneAX.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "backboneAX/version"
2
+
3
+ if defined? Rails
4
+ if Rails.version.to_f >= 3.1
5
+ require "backboneAX/engine"
6
+ end
7
+ end
8
+
9
+ require "backboneAX/bootstrap_view"
10
+ module Sprockets::Helpers::RailsHelper
11
+ include BackboneAX::BootstrapView
12
+ end
@@ -0,0 +1,36 @@
1
+ class Bx.Collection.Base extends Backbone.Collection
2
+
3
+ constructor: (options = {}) ->
4
+ super(options)
5
+ @models = []
6
+ @fetchCalled = false
7
+
8
+ fetch: (options = {}) ->
9
+ @fetchCalled = true
10
+ @_connState("connected")
11
+
12
+ optionsSuccess = options.success
13
+ options.success = (collection, response) =>
14
+ @_connState()
15
+ optionsSuccess(collection, response) if optionsSuccess
16
+
17
+ optionsError = options.error
18
+ options.error = (collection, response) =>
19
+ @_connState()
20
+ optionsError(collection, response) if optionsError
21
+
22
+ super(options)
23
+
24
+ fetchOnce: (options = {}) ->
25
+ return if @fetchCalled
26
+ @fetch(options)
27
+
28
+ _connState: (state = "") ->
29
+ @_conn_state = state
30
+ @trigger("change:connection")
31
+
32
+ isConnected: ()->
33
+ @_conn_state == "connected"
34
+
35
+ isFetched: ()->
36
+ @fetchCalled && !@isConnected()
@@ -0,0 +1,89 @@
1
+ class Bx.Collection.Paginate extends Bx.Collection.Base
2
+
3
+ constructor: (options = {}) ->
4
+ super(options)
5
+ @pageSize = options.pageSize ? 10
6
+ @pageCurrent = options.pageCurrent ? 0
7
+ @pageTotal = options.pageTotal ? 1
8
+ @current = options.current ? null
9
+
10
+ parse: (response) ->
11
+ @pageCurrent = if response.pagination then response.pagination.current ? 1 else 1
12
+ @pageTotal = if response.pagination then response.pagination.total ? 1 else 1
13
+ response.items || []
14
+
15
+ fetch: (options = {}) ->
16
+ options.data = $.extend(options.data || {}, {page: @pageCurrent, pageSize: @pageSize})
17
+
18
+ if @current? && @current.isNew()
19
+ optionsSuccess = options.success
20
+ options.success = (collection, response) =>
21
+ first = collection.first()
22
+ @currentSet(first.id) if first?
23
+ optionsSuccess(collection, response) if optionsSuccess
24
+
25
+ super(options)
26
+
27
+ # RESTART THE SEARCH
28
+ restart: (options = {}) ->
29
+ options.add = false
30
+ @pageCurrent = 1
31
+ @fetch(options)
32
+
33
+ # PREV PAGE / NEXT PAGE
34
+ prev: (options = {}) ->
35
+ if @pageCurrent > 0
36
+ @pageCurrent--
37
+ @fetch(options)
38
+
39
+ hasPrev: () ->
40
+ @pageCurrent > 1
41
+
42
+ next: (options = {}) ->
43
+ if @pageCurrent < @pageTotal
44
+ @pageCurrent++
45
+ @fetch(options)
46
+
47
+ hasNext: () ->
48
+ @pageCurrent < @pageTotal
49
+
50
+ # MORE PAGE
51
+ more: (options = {}) ->
52
+ options.add = true
53
+ if @pageCurrent < @pageTotal
54
+ @pageCurrent++
55
+ @fetch(options)
56
+
57
+ hasMore: () ->
58
+ @pageCurrent < @pageTotal
59
+
60
+ # CURRENT
61
+ currentSet: (id)->
62
+ if @current? && @current.id != parseInt(id, 10)
63
+ @current.set({id: id}, {silent: true})
64
+ @current.fetch();
65
+
66
+ currentPrev: () ->
67
+ return unless @current?
68
+ index = @indexOf(@current.id)
69
+ if index > 0
70
+ @currentSet(@at(index - 1).id)
71
+
72
+ hasCurrentPrev: () ->
73
+ return false unless @current?
74
+ index = @indexOf(@current.id)
75
+ return index > 0
76
+
77
+ currentNext: () ->
78
+ return unless @current?
79
+ index = @indexOf(@current.id)
80
+ if index < @size - 1
81
+ @currentSet(@at(index + 1).id)
82
+ else
83
+ @more()
84
+
85
+ hasCurrentNext: () ->
86
+ return false unless @current?
87
+ index = @indexOf(@current.id)
88
+ return (index < @size - 1) || @hasMore()
89
+
@@ -0,0 +1,7 @@
1
+ $.dateRawNow = ()->
2
+ jQuery.dateRawFormat(Date.today())
3
+
4
+ $.dateRawFormat = (date)->
5
+ return null unless date?
6
+ date.toString("yyyyMMddHHmm")
7
+
@@ -0,0 +1,73 @@
1
+ class Bx.Model.Base extends Backbone.Model
2
+
3
+ fetch: (options = {}) ->
4
+ @_connState("connected")
5
+
6
+ optionsSuccess = options.success
7
+ options.success = (model, response) =>
8
+ @_connState()
9
+ optionsSuccess(model, response) if optionsSuccess
10
+
11
+ optionsError = options.error
12
+ options.error = (model, response) =>
13
+ @_connState()
14
+ optionsError(model, response) if optionsError
15
+
16
+ super(options)
17
+
18
+ save: (attr, options = {}) ->
19
+ @_connState("connected")
20
+
21
+ optionsSuccess = options.success
22
+ options.success = (model, response) =>
23
+ @_connState()
24
+ optionsSuccess(model, response) if optionsSuccess
25
+
26
+ optionsError = options.error
27
+ options.error = (model, response) =>
28
+ @_connState()
29
+ optionsError(model, response) if optionsError
30
+
31
+ super(attr, options)
32
+
33
+ destroy: (options = {}) ->
34
+ @_connState("connected")
35
+
36
+ optionsSuccess = options.success
37
+ options.success = (model, response) =>
38
+ @_connState()
39
+ optionsSuccess(model, response) if optionsSuccess
40
+
41
+ optionsError = options.error
42
+ options.error = (model, response) =>
43
+ @_connState()
44
+ optionsError(model, response) if optionsError
45
+
46
+ super(options)
47
+
48
+ _connState: (state = "") ->
49
+ @_conn_state = state
50
+ @trigger("change:connection")
51
+
52
+ isConnected: () ->
53
+ @_conn_state == "connected"
54
+
55
+
56
+ getDate: (attr, format = null) ->
57
+ value = @get(attr)
58
+ return null unless value?
59
+ switch format
60
+ when "raw"
61
+ value
62
+ when "dateLong"
63
+ Date.parseExact(value, "yyyyMMddHHmm").toString("dddd MMMM d, yyyy")
64
+ when "date"
65
+ Date.parseExact(value, "yyyyMMddHHmm").toString("d MMM yy")
66
+ when "timeLong"
67
+ Date.parseExact(value, "yyyyMMddHHmm").toString("h:mm tt")
68
+ when "time"
69
+ Date.parseExact(value, "yyyyMMddHHmm").toString("HH:mm")
70
+ when "dateTimeLong"
71
+ Date.parseExact(value, "yyyyMMddHHmm").toString("dddd MMMM d, yyyy h:mm tt")
72
+ else
73
+ Date.parseExact(value, "yyyyMMddHHmm").toString("d MMM yyyy")
@@ -0,0 +1,13 @@
1
+ class Bx.Pool
2
+ @fill: (datasets)->
3
+ _.each datasets, (e) ->
4
+ if e.dataset && e.dataset.model
5
+ Bx.Model.Pool.get(e.dataset.model).set(JSON.parse($(e).text()), {silent: true})
6
+ else if e.dataset && e.dataset.collection
7
+ Gec.CollectionPool.get(e.dataset.collection).reset(JSON.parse($(e).text()))
8
+ else if e.dataset && e.dataset.array
9
+ data = Bx.ArrayPool.get(e.dataset.array)
10
+ $.extend(data, JSON.parse($(e).text()))
11
+ else if e.dataset && e.dataset.hash
12
+ data = Bx.HashPool.get(e.dataset.hash)
13
+ $.extend(data, JSON.parse($(e).text()))
@@ -0,0 +1,4 @@
1
+ class Bx.ArrayPool extends Bx.Poolable
2
+
3
+ @_create: (name) ->
4
+ []
@@ -0,0 +1,4 @@
1
+ class Bx.Collection.BasePool extends Bx.Poolable
2
+
3
+ @_create: (name) ->
4
+ new Backbone.Collection
@@ -0,0 +1,4 @@
1
+ class Bx.HashPool extends Bx.Poolable
2
+
3
+ @_create: (name) ->
4
+ {}
@@ -0,0 +1,5 @@
1
+ class Bx.Model.Pool extends Bx.Poolable
2
+
3
+ @_create: (name) ->
4
+ new Backbone.Model
5
+
@@ -0,0 +1,21 @@
1
+ class Bx.Poolable
2
+ @reset: (name) ->
3
+ return unless @_data?
4
+ if name?
5
+ @_data[name] = null
6
+ else
7
+ @_data = {}
8
+
9
+ @has: (name) ->
10
+ return false unless @_data?
11
+ @_data[name]?
12
+
13
+ @get: (name, reset = false) ->
14
+ @_data ||= {}
15
+ if !@_data[name]? || reset
16
+ @_data[name] = @_create(name)
17
+ @_data[name]
18
+
19
+ @_create: (name) ->
20
+ "should be overridden"
21
+
@@ -0,0 +1,16 @@
1
+ class Bx.Router.Base extends Backbone.Router
2
+
3
+ navigate: (path, triggerRoutes) ->
4
+ if !path? || path.length == 0
5
+ path = $.cookie("redirect")
6
+
7
+ if !path? || path.length == 0
8
+ path = '/'
9
+
10
+ super(path, triggerRoutes)
11
+
12
+ setRedirect: (path) ->
13
+ $.cookie("redirect", path, 1)
14
+
15
+ resetRedirect: () ->
16
+ $.cookie("redirect", "")
@@ -0,0 +1,26 @@
1
+ class Bx.View.Base extends Backbone.View
2
+
3
+ constructor: (options) ->
4
+ super(options)
5
+ @_views = []
6
+ # allow overriding of the "contructed" method
7
+ @constructed(options) if @constructed?
8
+
9
+ remove: () ->
10
+ super()
11
+ _.each @_views, (view) ->
12
+ view.remove()
13
+ # allow overriding of the "removed" method
14
+ @removed() if @removed?
15
+
16
+ # CHILD VIEWS
17
+ createView: (klass, options = {}) ->
18
+ view = new klass(options)
19
+ @_views.push(view)
20
+ return view
21
+
22
+ removeView: (view) ->
23
+ view.remove()
24
+ @_views = _.reject @_views, (object) ->
25
+ object == view
26
+ return null
@@ -0,0 +1,87 @@
1
+ _.extend Backbone.View.prototype,
2
+
3
+ formSetText: (fieldName, model) ->
4
+ value = if @_isModel(model) then model.get(fieldName) else model
5
+ field = @$("##{fieldName}")
6
+
7
+ field.attr('value', value)
8
+
9
+ formGetText: (fieldName, model) ->
10
+ field = @$("##{fieldName}")
11
+ value = field.attr('value')
12
+
13
+ if model?
14
+ options = {}
15
+ options[fieldName] = value
16
+ model.set(options, {silent: true})
17
+ return value
18
+
19
+ formSetDate: (fieldName, model) ->
20
+ value = if @_isModel(model) then model.getDate(fieldName) else model
21
+ field = @$("##{fieldName}")
22
+
23
+ field.attr('value', value)
24
+
25
+ formSetSelect: (fieldName, model) ->
26
+ value = if @_isModel(model) then model.get(fieldName) else model
27
+ field = @$("##{fieldName}")
28
+
29
+ field.find("option").removeAttr('selected')
30
+ field.find("option[value='#{value}']").attr('selected', true)
31
+
32
+ formGetSelect: (fieldName, model) ->
33
+ field = @$("##{fieldName}")
34
+ value = field.find('option:selected').val()
35
+
36
+ if model?
37
+ options = {}
38
+ options[fieldName] = value
39
+ model.set(options, {silent: true})
40
+ return value
41
+
42
+ formSetSelectMultiple: (fieldName, model) ->
43
+ values = if @_isModel(model) then model.get(fieldName) else model
44
+ field = @$("##{fieldName}")
45
+
46
+ field.find("option").removeAttr('selected')
47
+ if values?
48
+ _.each values, (value) ->
49
+ field.find("option[value='#{value}']").attr('selected', true)
50
+
51
+ formGetSelectMultiple: (fieldName, model) ->
52
+ field = @$("##{fieldName}")
53
+
54
+ values = []
55
+ _.each field.find('option'), (option) ->
56
+ if $(option).is(':selected')
57
+ values.push($(option).val())
58
+
59
+ if model?
60
+ options = {}
61
+ options[fieldName] = values
62
+ model.set(options, {silent: true})
63
+ return values
64
+
65
+ formSetCheckbox: (fieldName, model) ->
66
+ value = if @_isModel(model) then model.get(fieldName) else model
67
+ field = @$("##{fieldName}")
68
+
69
+ if value == true
70
+ field.attr('checked', true)
71
+ else
72
+ field.removeAttr('checked')
73
+
74
+ formGetCheckbox: (fieldName, model) ->
75
+ field = @$("##{fieldName}")
76
+ value = field.is(':checked')
77
+
78
+ if model?
79
+ options = {}
80
+ options[fieldName] = value
81
+ model.set(options, {silent: true})
82
+ return value
83
+
84
+ #private methods
85
+ _isModel= (model) ->
86
+ model? && typeof(model) == 'object'
87
+
@@ -0,0 +1,104 @@
1
+ _.extend Backbone.View.prototype,
2
+ _isModel: (model) ->
3
+ model? && typeof(model) == 'object'
4
+
5
+ setTemplate: (model, $scope = null) ->
6
+ fields = if $scope? then $("*[data-setter]", $scope) else @$("*[data-setter]")
7
+ _.each fields, (field) =>
8
+ $field = $(field)
9
+ setters= $field.attr("data-setter").split(";");
10
+ _.each setters, (setter) =>
11
+ setdata = setter.split(',')
12
+ setdata.push("text") if (setdata.length == 1 )
13
+ switch $.trim(setdata[1])
14
+ when "id"
15
+ @setTemplateId($.trim(setdata[0]), model, $scope, $field)
16
+ when "text"
17
+ @setTemplateText($.trim(setdata[0]), model, $scope, $field)
18
+ when "date"
19
+ @setTemplateDate($.trim(setdata[0]), model, $scope, $field)
20
+ when "bool"
21
+ @setTemplateBool($.trim(setdata[0]), model, $scope, $field)
22
+ when "array"
23
+ @setTemplateArray($.trim(setdata[0]), model, $scope, $field)
24
+ when "show"
25
+ @setTemplateShow($.trim(setdata[0]), model, $scope, $field)
26
+ when "hide"
27
+ @setTemplateHide($.trim(setdata[0]), model, $scope, $field)
28
+ when "img"
29
+ @setTemplateImg($.trim(setdata[0]), model, $scope, $field)
30
+ when "href"
31
+ @setTemplateHref($.trim(setdata[0]), model, $scope, $field)
32
+ else
33
+ @setTemplateText($.trim(setdata[0]), model, $scope, $field)
34
+
35
+ setTemplateId: (fieldName, model, $scope, $field) ->
36
+ value = if @_isModel(model) then model.get(fieldName) else model
37
+ field = if $field? then $field else if $scope? then $("##{fieldName}", $scope) else @$("##{fieldName}")
38
+
39
+ field.attr(id, value)
40
+
41
+ setTemplateText: (fieldName, model, $scope, $field) ->
42
+ value = if @_isModel(model) then model.get(fieldName) else model
43
+ field = if $field? then $field else if $scope? then $("##{fieldName}", $scope) else @$("##{fieldName}")
44
+
45
+ field.html(value)
46
+
47
+ setTemplateDate: (fieldName, model, $scope, $field) ->
48
+ value = if @_isModel(model) then model.getDate(fieldName) else model
49
+ field = if $field? then $field else if $scope? then $("##{fieldName}", $scope) else @$("##{fieldName}")
50
+
51
+ field.html(value)
52
+
53
+ setTemplateBool: (fieldName, model, $scope, $field) ->
54
+ value = if @_isModel(model) then model.get(fieldName) else model
55
+ field = if $field? then $field else if $scope? then $("##{fieldName}", $scope) else @$("##{fieldName}")
56
+
57
+ if value == true
58
+ field.addClass('truthy').removeClass('falsy')
59
+ else
60
+ field.addClass('falsy').removeClass('truthy')
61
+
62
+ setTemplateArray: (fieldName, model, $scope, $field) ->
63
+ values = if @_isModel(model) then model.get(fieldName) else model
64
+ field = if $field? then $field else if $scope? then $("##{fieldName}", $scope) else @$("##{fieldName}")
65
+
66
+ result = ""
67
+ if values?
68
+ _.each values, (value)->
69
+ if result.length > 0 then result += ", "
70
+ result += value
71
+
72
+ field.html(result)
73
+
74
+ setTemplateShow: (fieldName, model, $scope, $field) ->
75
+ value = if @_isModel(model) then model.get(fieldName) else model
76
+ field = if $field? then $field else if $scope? then $("##{fieldName}", $scope) else @$("##{fieldName}")
77
+
78
+ field.toggle(value == true)
79
+ if value == true
80
+ field.removeClass('hide')
81
+ else
82
+ field.addClass('hide')
83
+
84
+ setTemplateHide: (fieldName, model, $scope, $field) ->
85
+ value = if @_isModel(model) then model.get(fieldName) else model
86
+ field = if $field? then $field else if $scope? then $("##{fieldName}", $scope) else @$("##{fieldName}")
87
+
88
+ field.toggle(value != true)
89
+ if value == true
90
+ field.addClass('hide')
91
+ else
92
+ field.removeClass('hide')
93
+
94
+ setTemplateImg: (fieldName, model, $scope, $field) ->
95
+ value = if @_isModel(model) then model.get(fieldName) else model
96
+ field = if $field? then $field else if $scope? then $("##{fieldName}", $scope) else @$("##{fieldName}")
97
+
98
+ field.attr('src', value)
99
+
100
+ setTemplateHref: (fieldName, model, $scope, $field) ->
101
+ value = if @_isModel(model) then model.get('id') else model
102
+ field = if $field? then $field else if $scope? then $("##{fieldName}", $scope) else @$("##{fieldName}")
103
+
104
+ field.attr('href', "##{value}")
@@ -0,0 +1,55 @@
1
+ #= require_self
2
+ #= require_tree ./bx
3
+
4
+ window.Bx =
5
+ Model: {}
6
+ Collection: {}
7
+ Router: {}
8
+ View: {}
9
+
10
+ Bx.manageErrors = () ->
11
+ $(document).ajaxError (event, response) ->
12
+ if (response.status == 200)
13
+ # ignore it
14
+ else if (response.status == 401)
15
+ errorResponse = $.parseJSON(response.responseText)
16
+ error = errorResponse.error
17
+ Bx.Model.Pool.get('alert').set
18
+ importance: "error"
19
+ header: "Login Required"
20
+ message: error ? "Invalid Login Details"
21
+ fields: {
22
+ email: ""
23
+ password: ""
24
+ }
25
+ window.router.navigate('/login', true)
26
+
27
+ else if (response.status == 403)
28
+ errorResponse = $.parseJSON(response.responseText)
29
+ error = errorResponse.error
30
+ Bx.Model.Pool.get('alert').set
31
+ importance: "error"
32
+ header: "Access Denied"
33
+ message: error ? ""
34
+ fields: {
35
+ email: ""
36
+ password: ""
37
+ }
38
+ window.router.navigate('/', true)
39
+
40
+ else if (response.status == 404)
41
+ Bx.Model.Pool.get('alert').set
42
+ importance: "error"
43
+ header: "Server Error"
44
+ # document.write(response.responseText)
45
+
46
+ else if (response.status == 302)
47
+ redirectResponse = $.parseJSON(response.responseText)
48
+ window.router.navigate(redirectResponse.redirect, true)
49
+
50
+ else if (response.status != 500)
51
+ error = $.parseJSON(response.responseText)
52
+ Bx.Model.Pool.get('alert').set(error)
53
+
54
+ else if (response.status == 500)
55
+ document.write(response.responseText)
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backboneAX
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Douglas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-09 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: backbone Application Extensions for cleaner application development
15
+ email:
16
+ - dougo.chris@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Rakefile
24
+ - backboneAX.gemspec
25
+ - lib/backboneAX.rb
26
+ - lib/backboneAX/bootstrap_view.rb
27
+ - lib/backboneAX/engine.rb
28
+ - lib/backboneAX/version.rb
29
+ - vendor/assets/javascripts/bx.js.coffee
30
+ - vendor/assets/javascripts/bx/collection/base.js.coffee
31
+ - vendor/assets/javascripts/bx/collection/paginate.js.coffee
32
+ - vendor/assets/javascripts/bx/lib/date.js.coffee
33
+ - vendor/assets/javascripts/bx/model/base.js.coffee
34
+ - vendor/assets/javascripts/bx/pool/pool.js.coffee
35
+ - vendor/assets/javascripts/bx/pool/poolable.js.coffee
36
+ - vendor/assets/javascripts/bx/pool/poolable/array.js.coffee
37
+ - vendor/assets/javascripts/bx/pool/poolable/collection.js.coffee
38
+ - vendor/assets/javascripts/bx/pool/poolable/hash.js.coffee
39
+ - vendor/assets/javascripts/bx/pool/poolable/model.js.coffee
40
+ - vendor/assets/javascripts/bx/router/base.js.coffee
41
+ - vendor/assets/javascripts/bx/view/base.js.coffee
42
+ - vendor/assets/javascripts/bx/view/bx_form.js.coffee
43
+ - vendor/assets/javascripts/bx/view/bx_template.js.coffee
44
+ homepage: https://github.com/dougochris/backboneAX
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ segments:
57
+ - 0
58
+ hash: -3824191617726213984
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ segments:
66
+ - 0
67
+ hash: -3824191617726213984
68
+ requirements: []
69
+ rubyforge_project: backboneAX
70
+ rubygems_version: 1.8.10
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: backbone Application Extensions
74
+ test_files: []