type_station 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/type_station/editables/admin_bar.js.coffee +6 -0
  3. data/app/assets/javascripts/type_station/editables/edit_page.js.coffee +14 -3
  4. data/app/assets/javascripts/type_station/editables/file.js.coffee +1 -1
  5. data/app/assets/javascripts/type_station/editables/new_page.js.coffee +1 -0
  6. data/app/assets/javascripts/type_station/init.js.coffee +6 -3
  7. data/app/assets/javascripts/type_station/lib/models.js.coffee +7 -2
  8. data/app/assets/stylesheets/type_station/base.css.scss +2 -2
  9. data/app/models/type_station/content.rb +1 -1
  10. data/app/models/type_station/page.rb +16 -6
  11. data/app/presenters/type_station/page_presenter.rb +8 -2
  12. data/lib/type_station/version.rb +1 -1
  13. data/spec/dummy/app/views/pages/index_other.html.erb +3 -3
  14. data/spec/dummy/log/development.log +3724 -0
  15. data/spec/dummy/tmp/cache/assets/development/sass/fde2fd9fd4415e2893f7c202128d5909c847645f/base.css.scssc +0 -0
  16. data/spec/dummy/tmp/cache/assets/development/sprockets/0b230f1bf23bd7b1392e34cacde00da0 +0 -0
  17. data/spec/dummy/tmp/cache/assets/development/sprockets/0cbda04368ddbf6d761e788334075e7c +0 -0
  18. data/spec/dummy/tmp/cache/assets/development/sprockets/0d5a85a524a12561b8cfff4e8d06b332 +0 -0
  19. data/spec/dummy/tmp/cache/assets/development/sprockets/2155dbeb10a65c2519b49179b3bc6f3a +0 -0
  20. data/spec/dummy/tmp/cache/assets/development/sprockets/300f6f1e08668cacf691691df4d13889 +0 -0
  21. data/spec/dummy/tmp/cache/assets/development/sprockets/3a3d03c0a92f21419e1e85991774a28b +0 -0
  22. data/spec/dummy/tmp/cache/assets/development/sprockets/4144b15d96ec80b5c7fb367b57aaeef3 +0 -0
  23. data/spec/dummy/tmp/cache/assets/development/sprockets/579b1a727fe5b55dfe450b0835c56a65 +0 -0
  24. data/spec/dummy/tmp/cache/assets/development/sprockets/5a806147b739da644a296d2def76c243 +0 -0
  25. data/spec/dummy/tmp/cache/assets/development/sprockets/735d50df5dc976a13b56aa81f5970298 +0 -0
  26. data/spec/dummy/tmp/cache/assets/development/sprockets/73939a29e193b5a1fad031fa75f94119 +0 -0
  27. data/spec/dummy/tmp/cache/assets/development/sprockets/7ef9b3c736e553151f79c509136b1c44 +0 -0
  28. data/spec/dummy/tmp/cache/assets/development/sprockets/825bd4dba50f1ea2c0ae5e8a3708119e +0 -0
  29. data/spec/dummy/tmp/cache/assets/development/sprockets/84822f25094f67b515ad5f452381dcb0 +0 -0
  30. data/spec/dummy/tmp/cache/assets/development/sprockets/85d858ed64f06543161931735cb77748 +0 -0
  31. data/spec/dummy/tmp/cache/assets/development/sprockets/8803d0a63bbf3fce683c968d4a900480 +0 -0
  32. data/spec/dummy/tmp/cache/assets/development/sprockets/966db607ae0e7aad72cf171b8fec537a +0 -0
  33. data/spec/dummy/tmp/cache/assets/development/sprockets/99a40b6133b9eaa016bd6cf01fff987a +0 -0
  34. data/spec/dummy/tmp/cache/assets/development/sprockets/9c8cd77db76e28f0a074573a72509ce9 +0 -0
  35. data/spec/dummy/tmp/cache/assets/development/sprockets/9d5a258ab9e431a1a7eaf931ed4c3fb3 +0 -0
  36. data/spec/dummy/tmp/cache/assets/development/sprockets/a2b3a282d5d8a5c20444d1a27f70a61e +0 -0
  37. data/spec/dummy/tmp/cache/assets/development/sprockets/a87cf4d10d892fb23f2fc818d7ca7207 +0 -0
  38. data/spec/dummy/tmp/cache/assets/development/sprockets/bd3113e1418cbc640eb6e1b06d486163 +0 -0
  39. data/spec/dummy/tmp/cache/assets/development/sprockets/cb80f61fc678a70e99e16156ae6e07d1 +0 -0
  40. data/spec/dummy/tmp/cache/assets/development/sprockets/cdedc95319572f0c3e36a3a5a044572d +0 -0
  41. data/spec/dummy/tmp/cache/assets/development/sprockets/cf5014041f97c55eee7c67feddf11b81 +0 -0
  42. data/spec/dummy/tmp/cache/assets/development/sprockets/d3a2586089547d98e033029b94eb86a5 +0 -0
  43. data/spec/dummy/tmp/cache/assets/development/sprockets/d4248f8b11c6b21abffed4a5e718722d +0 -0
  44. data/spec/dummy/tmp/cache/assets/development/sprockets/dd9f84cc20227ad66bbd1f26bbc11ccc +0 -0
  45. data/spec/dummy/tmp/cache/assets/development/sprockets/e03c578b73cf9936edc84ff2b48c07da +0 -0
  46. data/spec/dummy/tmp/cache/assets/development/sprockets/ef7d0257e22920401b54d6662e627252 +0 -0
  47. data/spec/dummy/tmp/cache/assets/development/sprockets/f1567fa9088d43b2fb0f9a0caa1ed107 +0 -0
  48. data/spec/dummy/tmp/cache/assets/development/sprockets/f566af7037e0e3042b19bd5ee11b21c4 +0 -0
  49. data/vendor/assets/javascripts/jquery.textcomplete.js +1 -1
  50. data/vendor/assets/stylesheets/jquery.textcomplete.css +7 -7
  51. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec652817ab6918fbe486f6b374531705b2bfd2c8
4
- data.tar.gz: e4104767a7a20410f50a3da0509b8dd905894c89
3
+ metadata.gz: e507c0e25eee2de86875f7172277436418e1a4d2
4
+ data.tar.gz: 1903bb9f88c274a6170e11da85b6a63df96a3a70
5
5
  SHA512:
6
- metadata.gz: 5e4edd03b0122d983b77a0f15626e6356886e229d4b93dc15c18277023433a35c3b9ea1593ba8a119585e34bf66dbce7f35984355e6645517af4b10bbd1e4cb7
7
- data.tar.gz: 517a87e210d4281e1e85b6b806e9d93064d111786dfea52e84bb6bf296431d6a39aaa65fa19ab1ed9dba250cfbaf06a6d9c00229aec154e5eb318f4cdc978f88
6
+ metadata.gz: 8f713d3ced71678522a84a7c8a8ea9029aa6bc582bad598739b67bbfb183a2815d4acf3d9084114cc5f7b738b069d0baddf7f27237db9aae063b83b9c9c7677f
7
+ data.tar.gz: 246292b7fc6246cc8f2d898414a191be736c46865a936841eff17c7e1b1a5ebe22b1de13f40226f7ec8dca46eb6fc35153e9e2901978095100ea6fec1324519e
@@ -10,6 +10,12 @@ class window.TS.AdminBar
10
10
 
11
11
  $('#ts-admin-bar-cancel').on 'click', ->
12
12
  window.TS.disable()
13
+ if window.TS.isChanged()
14
+ vex.dialog.confirm
15
+ message: 'You have unsaved changes, Do you want to discard them?'
16
+ callback: (value) ->
17
+ if value
18
+ window.location.reload()
13
19
  false
14
20
 
15
21
  $('#ts-admin-bar-save').on 'click', ->
@@ -18,11 +18,13 @@ deletePage = (element) ->
18
18
 
19
19
  buildFields = (element) ->
20
20
  tsFields = element.data('tsFields')
21
+ tsFieldTypes = {}
21
22
  inputs = ''
22
23
  model = window.TS.getModel element.data('ts-url')
23
24
  modelValues = element.data('ts-data')['ts_values']
24
25
 
25
26
  for field in tsFields
27
+ tsFieldTypes[field.name] = field.type
26
28
  label = "<label for='#{field.name}'>#{field.label}</label>"
27
29
  input = switch field.type
28
30
  when "text" then "<input type='text' name='#{field.name}' id='#{field.name}' value='#{modelValues[field.name]}' />"
@@ -41,6 +43,7 @@ buildFields = (element) ->
41
43
  select
42
44
  inputs += "<div class'vex-custom-field-wrapper'>#{label}<div class='vex-custom-input-wrapper'>#{input}</div></div>"
43
45
 
46
+ element.data('tsFieldTypes', tsFieldTypes)
44
47
  inputs
45
48
 
46
49
  class window.TS.EditPage
@@ -53,6 +56,12 @@ class window.TS.EditPage
53
56
  when 'left_to_right'
54
57
  $(element).append($('<span>').addClass('ts-editable-button').addClass('ts-move-up-button').addClass('ts-button').html("<i class='ion-arrow-left-b'></i>"))
55
58
  $(element).append($('<span>').addClass('ts-editable-button').addClass('ts-move-down-button').addClass('ts-button').html("<i class='ion-arrow-right-b'></i>"))
59
+ when 'invert_left_to_right'
60
+ $(element).append($('<span>').addClass('ts-editable-button').addClass('ts-move-down-button-invert').addClass('ts-button').html("<i class='ion-arrow-left-b'></i>"))
61
+ $(element).append($('<span>').addClass('ts-editable-button').addClass('ts-move-up-button-invert').addClass('ts-button').html("<i class='ion-arrow-right-b'></i>"))
62
+ when 'invert'
63
+ $(element).append($('<span>').addClass('ts-editable-button').addClass('ts-move-down-button-invert').addClass('ts-button').html("<i class='ion-arrow-up-b'></i>"))
64
+ $(element).append($('<span>').addClass('ts-editable-button').addClass('ts-move-up-button-invert').addClass('ts-button').html("<i class='ion-arrow-down-b'></i>"))
56
65
  else
57
66
  $(element).append($('<span>').addClass('ts-editable-button').addClass('ts-move-up-button').addClass('ts-button').html("<i class='ion-arrow-up-b'></i>"))
58
67
  $(element).append($('<span>').addClass('ts-editable-button').addClass('ts-move-down-button').addClass('ts-button').html("<i class='ion-arrow-down-b'></i>"))
@@ -72,6 +81,7 @@ class window.TS.EditPage
72
81
  callback: (data) ->
73
82
  if data
74
83
  $el = @$element
84
+ tsFieldTypes = $el.data('tsFieldTypes')
75
85
  model = window.TS.getModel $el.data('ts-url')
76
86
 
77
87
  vex.dialog.confirm
@@ -79,13 +89,14 @@ class window.TS.EditPage
79
89
  callback: (value) ->
80
90
  if value
81
91
  for k,v of data
82
- model.set(k, { field: k, value: v, type: if $.isArray(v) then 'multiple_select' else 'text' })
92
+ type = tsFieldTypes[k]
93
+ model.set(k, { field: k, value: v, type: if type == 'multiple_select' then 'multiple_select' else 'text' })
83
94
  model.save ->
84
95
  window.location.reload()
85
96
 
86
- $('.ts-move-up-button', @elements).on 'click', ->
97
+ $('.ts-move-up-button, .ts-move-up-button-invert', @elements).on 'click', ->
87
98
  move $(@).parent(), 'move_up'
88
- $('.ts-move-down-button', @elements).on 'click', ->
99
+ $('.ts-move-down-button, .ts-move-down-button-invert', @elements).on 'click', ->
89
100
  move $(@).parent(), 'move_down'
90
101
 
91
102
  $('.ts-delete-page-button', @elements).on 'click', ->
@@ -20,7 +20,7 @@ buildUploader = (element, data)->
20
20
  .bind 'cloudinarydone', (e, data) ->
21
21
  $element = $("##{$(this).data('elementId')}")
22
22
  for imageTag in $('.ts-editable-link-tag', $element)
23
- $(imageTag).attr('href', $.cloudinary.url(data.result.public_id, {}))
23
+ $(imageTag).attr('href', $.cloudinary.url(data.result.public_id, {resource_type: 'raw'}))
24
24
  $element.data('drop').close()
25
25
  $(this).prop('disabled', false)
26
26
  $('.ts-progress-bar').remove()
@@ -68,6 +68,7 @@ class window.TS.NewPage
68
68
  data: JSON.stringify(json)
69
69
  success: (data, status) -> window.location.reload()
70
70
  else
71
+ vex.dialog.buttons.YES.text = 'Ok'
71
72
  vex.dialog.alert
72
73
  message: 'Please fill in all required fields'
73
74
  callback: ->
@@ -23,9 +23,7 @@ window.TS.enable = ->
23
23
  @editors.each (id, editor) -> editor.enable()
24
24
  @onEnabled()
25
25
  $(window).on 'beforeunload', =>
26
- dirtyArray = []
27
- @models.each (id, model) -> dirtyArray.push model.isChanged()
28
- if $.grep(dirtyArray, (a) -> a == true ).length > 0
26
+ if @isChanged()
29
27
  return 'You have unsaved changes. Are you sure you want to leave?'
30
28
  else
31
29
  return
@@ -42,6 +40,11 @@ window.TS.save = ->
42
40
  @models.each (id, model) -> model.save()
43
41
  @onSaved()
44
42
 
43
+ window.TS.isChanged = ->
44
+ dirtyArray = []
45
+ @models.each (id, model) -> dirtyArray.push model.isChanged()
46
+ $.grep(dirtyArray, (a) -> a == true ).length > 0
47
+
45
48
  window.TS.init = ->
46
49
  @editors.set 'ts-admin-bar', new window.TS.AdminBar $('#ts-admin-bar-template')
47
50
  @editors.set 'ts-editable-text', new window.TS.EditableText $('span.ts-editable-text')
@@ -18,10 +18,13 @@ class window.TS.Model extends window.TS.Store
18
18
  super key, value
19
19
  @DIRTY[key] = 1
20
20
 
21
-
22
21
  changedKeys: -> Object.keys(@DIRTY)
23
22
  isChanged: -> @changedKeys().length > 0
24
23
 
24
+ _reset: ->
25
+ @STORE = {}
26
+ @DIRTY = {}
27
+
25
28
  save: (callback = ->) ->
26
29
  self = @
27
30
  data = []
@@ -35,4 +38,6 @@ class window.TS.Model extends window.TS.Store
35
38
  dataType: 'json'
36
39
  contentType: 'application/json'
37
40
  data: JSON.stringify({contents: data})
38
- success: (data) -> callback(data)
41
+ success: (data) ->
42
+ self._reset() #reset model to a clean state
43
+ callback(data)
@@ -80,14 +80,14 @@ bottom: auto;
80
80
  left: auto;
81
81
  }
82
82
 
83
- .ts-move-up-button {
83
+ .ts-move-up-button, .ts-move-down-button-invert {
84
84
  top: 0px;
85
85
  right: 120px;
86
86
  bottom: auto;
87
87
  left: auto;
88
88
  }
89
89
 
90
- .ts-move-down-button {
90
+ .ts-move-down-button, .ts-move-up-button-invert {
91
91
  top: 0px;
92
92
  right: 80px;
93
93
  bottom: auto;
@@ -15,7 +15,7 @@ module TypeStation
15
15
 
16
16
  # VALIDATIONS
17
17
 
18
- validates :name, presence: true
18
+ validates :name, presence: true, uniqueness: { scope: :type }
19
19
  validates :type, presence: true
20
20
 
21
21
  # INSTANT METHODS
@@ -55,15 +55,17 @@ module TypeStation
55
55
 
56
56
  def update_contents(params)
57
57
  params.each do |data|
58
- if content?(data[:field])
59
- set(data[:field], data[:value])
58
+ field, value, type = data[:field].to_sym, data[:value], data[:type].to_sym
59
+
60
+ if page_fields?(field) && !changed.include?(field) #and not changed already
61
+ self[field] = value
60
62
  else
61
- if self[data[:field]].present? && !changed.include?(data[:field].to_sym) #and not changed already
62
- self[data[:field]] = data[:value]
63
+ if content?(field)
64
+ set(field, value)
63
65
  else
64
- contents.build(name: data[:field], type: data[:type]).set(data[:value])
66
+ contents.build(name: field, type: type).set(value)
65
67
  end
66
- end
68
+ end
67
69
  end
68
70
 
69
71
  save
@@ -90,6 +92,10 @@ module TypeStation
90
92
  content_attributes[key].present?
91
93
  end
92
94
 
95
+ def page_fields?(key)
96
+ page_fields.include?(key)
97
+ end
98
+
93
99
  def content_attributes
94
100
  @content_attributes ||= Hash[self.contents.map {|c| [c.name, c]}]
95
101
  end
@@ -114,6 +120,10 @@ module TypeStation
114
120
 
115
121
  private
116
122
 
123
+ def page_fields
124
+ @page_fields ||= self.class.fields.keys.map(&:to_sym)
125
+ end
126
+
117
127
  # Generates a slug based of the title give by the user
118
128
  def generate_slug
119
129
  self.slug = root? ? "" : title.parameterize
@@ -30,12 +30,18 @@ module TypeStation
30
30
  @parent ||= PagePresenter.new(page.parent, @template)
31
31
  end
32
32
 
33
+ def root
34
+ @root ||= PagePresenter.new(TypeStation::Page.root, @template)
35
+ end
36
+
33
37
  private
34
38
 
35
39
  def build_content_methods
36
40
  page.content_attributes.each do |key, content_object|
37
- define_singleton_method key do
38
- ContentPresenter.new(content_object, @template)
41
+ unless page.page_fields? key
42
+ define_singleton_method key do
43
+ ContentPresenter.new(content_object, @template)
44
+ end
39
45
  end
40
46
  end
41
47
  end
@@ -2,7 +2,7 @@ module TypeStation
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 3
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
8
8
  end
@@ -91,14 +91,14 @@
91
91
  proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
92
92
  <%- end %>
93
93
 
94
- <%= ts_new :page, @page, content_tag: :div, fields: [{name: :title, type: 'text', label: 'Section name'}, {name: :template_name, type: 'select', label: 'Section template', options: [['Cool', 'v'], ['Blah', 'b']]}, {name: :test_value, type: 'text', label: 'test value'}, {name: :another_test, type: 'textarea', label: 'Blah'}, {name: :tags, type: 'multiple_select', label: 'Tags', options: [['Cool', 'v'], ['Blah', 'b'], ['sdfsdfdf', 'dd']]}], data: {name: 'Section', default: {type: :hidden, name: :section}} do %>
94
+ <%= ts_new :page, @page, content_tag: :div, fields: [{name: :title, type: 'text', label: 'Section name'}, {name: :redirect_to, type: 'text', label: 'Redirect'}, {name: :template_name, type: 'select', label: 'Section template', options: [['Cool', 'v'], ['Blah', 'b']]}, {name: :test_value, type: 'text', label: 'test value'}, {name: :another_test, type: 'textarea', label: 'Blah'}, {name: :tags, type: 'multiple_select', label: 'Tags', options: [['Cool', 'v'], ['Blah', 'b'], ['sdfsdfdf', 'dd']]}], data: {name: 'Section', default: {type: :hidden, name: :section}} do %>
95
95
  <h1>New Section</h1>
96
96
  <%- end %>
97
97
 
98
98
  <ul>
99
99
  <%- ts_pages(:section, @page).each do |page| %>
100
- <%= ts_edit :page, page, content_tag: :li, fields: [{name: :title, type: 'text', label: 'Section name'}, {name: :template_name, type: 'select', label: 'Section template', options: [['Cool', 'v'], ['Blah', 'b']]}, {name: :test_value, type: 'text', label: 'test value'}, {name: :another_test, type: 'textarea', label: 'Blah'}, {name: :tags, type: 'multiple_select', label: 'Tags', options: [['Cool', 'v'], ['Blah', 'b'], ['sdfsdfdf', 'dd']]}], data: {name: 'Section', default: {type: :hidden, name: :section}, moveable: 'left_to_right'} do %>
101
- <%= page.title %> - <%= page.test_value.value %> - <%= page.template_name %> - <%= page.another_test.value %> - <%= page.try(:tags).try(:value) %></li>
100
+ <%= ts_edit :page, page, content_tag: :li, fields: [{name: :title, type: 'text', label: 'Section name'}, {name: :redirect_to, type: 'text', label: 'Redirect'}, {name: :template_name, type: 'select', label: 'Section template', options: [['Cool', 'v'], ['Blah', 'b']]}, {name: :test_value, type: 'text', label: 'test value'}, {name: :another_test, type: 'textarea', label: 'Blah'}, {name: :tags, type: 'multiple_select', label: 'Tags', options: [['Cool', 'v'], ['Blah', 'b'], ['sdfsdfdf', 'dd']]}], data: {name: 'Section', default: {type: :hidden, name: :section}, moveable: 'left_to_right'} do %>
101
+ <%= page.title %> - <%= page.test_value.value %> - <%= page.template_name %> - <%= page.another_test.value %> - <%= page.try(:tags).try(:value) %> - <%= page.redirect_to %></li>
102
102
  <%- end %>
103
103
  <%- end %>
104
104
  </ul>