caboose-cms 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,7 @@
14
14
  //= require jquery_ujs
15
15
  //= require colorbox-rails
16
16
  //= require caboose/modal_integration
17
- //= require jquery.ui.all
18
- //= require tinymce-jquery
19
- //= require modeljs.all
17
+ /* require jquery.ui.all */
18
+ /* require tinymce-jquery */
19
+ /* require modeljs.all */
20
+
@@ -23,13 +23,3 @@ function fix_colorbox() {
23
23
  //h = $('#cboxLoadedContent').height();
24
24
  //$('#cboxLoadedContent').css('height', ''+(h+28)+'px');
25
25
  }
26
-
27
- //lastkeys = "";
28
- //$(document).keyup(function(e) {
29
- // if (e.keyCode == 13 && (lastkeys == "caboose" || lastkeys == "CABOOSE"))
30
- // $.colorbox({ href: '/station', iframe: true, initialWidth: 200, initialHeight: 50, innerWidth: 200, innerHeight: 50, scrolling: false, transition: 'fade', closeButton: false, onComplete: fix_colorbox, opacity: 0.50 });
31
- //
32
- // lastkeys += String.fromCharCode(e.keyCode);
33
- // if (lastkeys.length > 7)
34
- // lastkeys = lastkeys.substr(1);
35
- //});
@@ -4,6 +4,7 @@
4
4
  //= require caboose/model/model_binder
5
5
  //= require caboose/model/bound_control
6
6
  //= require caboose/model/bound_checkbox
7
+ //= require caboose/model/bound_image
7
8
  //= require caboose/model/bound_select
8
9
  //= require caboose/model/bound_text
9
10
  //= require caboose/model/bound_textarea
@@ -34,9 +34,7 @@ BoundCheckbox = BoundControl.extend({
34
34
  .attr('type', 'checkbox')
35
35
  .css('left', $('#'+this.placeholder).outerWidth() + 10)
36
36
  .attr('checked', this.attribute.value)
37
- .on('change', function() {
38
- this2.binder.cancel_active();
39
- this2.binder.active_control = this;
37
+ .on('change', function() {
40
38
  this2.save();
41
39
  })
42
40
  );
@@ -67,7 +65,6 @@ BoundCheckbox = BoundControl.extend({
67
65
  if (resp.error) this2.error(resp.error);
68
66
  else
69
67
  {
70
- this2.binder.active_control = this2;
71
68
  if (this2.binder.success)
72
69
  this2.binder.success(this2);
73
70
  this2.view();
@@ -0,0 +1,93 @@
1
+
2
+ BoundImage = BoundControl.extend({
3
+
4
+ //el: false,
5
+ //model: false,
6
+ //attribute: false,
7
+ //binder: false,
8
+
9
+ width: 100,
10
+ style: 'medium',
11
+ authenticity_token: false,
12
+
13
+ init: function(params) {
14
+ for (var thing in params)
15
+ this[thing] = params[thing];
16
+
17
+ this.el = this.el ? this.el : this.model.name.toLowerCase() + '_' + this.model.id + '_' + this.attribute.name;
18
+
19
+ var this2 = this;
20
+ $('#'+this.el).wrap($('<div/>').attr('id', this.el + '_container').css('position', 'relative'));
21
+ $('#'+this.el+'_container').empty();
22
+
23
+ $('#'+this.el+'_container').append($('<img/>')
24
+ .attr('src', this.attribute.value)
25
+ .css('width', this.width)
26
+ .css('float', 'left')
27
+ .css('margin-right', 10)
28
+ );
29
+ $('#'+this.el+'_container').append($('<form/>')
30
+ .attr('action', this.attribute.update_url)
31
+ .attr('method', 'post')
32
+ .attr('enctype', 'multipart/form-data')
33
+ .attr('encoding', 'multipart/form-data')
34
+ .attr('target', this.el + '_iframe')
35
+ .on('submit', function() {
36
+ $('#'+this2.el+'_message').html("<p class='loading'>Uploading...</p>");
37
+ $('#'+this2.el+'_iframe').on('load', function() { this2.post_upload(); });
38
+ })
39
+ .append($('<input/>').attr('type', 'hidden').attr('name', 'authenticity_token').val(this.binder.authenticity_token))
40
+ .append($('<input/>').attr('type', 'button').val('Update').click(function() { $('#'+this2.el+'_container input[type="file"]').click(); }))
41
+ .append($('<input/>')
42
+ .attr('type', 'file')
43
+ .attr('name', this.attribute.name)
44
+ .css('display', 'none')
45
+ .on('change', function() { $('#'+this2.el+'_container form').submit(); })
46
+ )
47
+ );
48
+ $('#'+this.el+'_container').append($('<div/>')
49
+ .attr('id', this.el + '_message')
50
+ );
51
+ $('#'+this.el+'_container').append($('<iframe/>')
52
+ .attr('name', this.el + '_iframe')
53
+ .attr('id', this.el + '_iframe')
54
+ .css('width', 0)
55
+ .css('height', 0)
56
+ .css('border', 0)
57
+ );
58
+ $('#'+this.el+'_container').append($('<br/>')
59
+ .css('clear', 'both')
60
+ );
61
+ },
62
+
63
+ post_upload: function() {
64
+ $('#'+this.el+'_message').empty();
65
+
66
+ var str = frames[this.el+'_iframe'].document.documentElement.innerHTML;
67
+ str = str.replace(/<body>(.*?)<\/body>/, '$1');
68
+ str = str.replace(/<html>(.*?)<\/html>/, '$1');
69
+ str = str.replace(/<head>.*?<\/head>(.*?)/, '$1');
70
+
71
+ var resp = $.parseJSON(str);
72
+ if (resp.error)
73
+ this.error(resp.error);
74
+ else if (resp.url)
75
+ $('#'+this.el+'_container img').attr('src', resp.url);
76
+ },
77
+
78
+ error: function(str) {
79
+ if (!$('#'+this.el+'_message').length)
80
+ {
81
+ $('#'+this.el+'_container').append($('<div/>')
82
+ .attr('id', this.el + '_message')
83
+ .css('width', $('#'+this.el).outerWidth())
84
+ );
85
+ }
86
+ $('#'+this.el+'_message').hide();
87
+ $('#'+this.el+'_message').html("<p class='note error'>" + str + "</p>");
88
+ $('#'+this.el+'_message').slideDown();
89
+ var this2 = this;
90
+ setTimeout(function() { $('#'+this2.el+'_message').slideUp(function() { $(this).empty(); }); }, 3000);
91
+ }
92
+
93
+ });
@@ -7,6 +7,7 @@ BoundText = BoundControl.extend({
7
7
  //binder: false,
8
8
 
9
9
  width: false,
10
+ save_attempts: 0,
10
11
 
11
12
  init: function(params) {
12
13
  for (var thing in params)
@@ -32,7 +33,13 @@ BoundText = BoundControl.extend({
32
33
  else
33
34
  $('#'+this2.el).removeClass('dirty');
34
35
  });
35
- $('#'+this.el).on('blur', function() { this2.save(); });
36
+ $('#'+this.el).on('blur', function() {
37
+ if (this2.save_attempts < 1)
38
+ {
39
+ this2.save_attempts++;
40
+ this2.save();
41
+ }
42
+ });
36
43
  },
37
44
 
38
45
  save: function() {
@@ -43,6 +50,7 @@ BoundText = BoundControl.extend({
43
50
  this.show_loader();
44
51
  var this2 = this;
45
52
  this.model.save(this.attribute, function(resp) {
53
+ this2.save_attempts = 0;
46
54
  if (resp.error)
47
55
  {
48
56
  this2.hide_loader();
@@ -6,6 +6,7 @@ ModelBinder.prototype = {
6
6
  controls: [],
7
7
  //active_control: false,
8
8
  success: false,
9
+ authenticity_token: false,
9
10
 
10
11
  init: function(params) {
11
12
  this.model = new Model({
@@ -14,8 +15,9 @@ ModelBinder.prototype = {
14
15
  attributes: [],
15
16
  attributes_clean: []
16
17
  });
17
- if (params['update_url']) this.model.update_url = params['update_url'];
18
- if (params['success']) this.success = params['success'];
18
+ if (params['update_url']) this.model.update_url = params['update_url'];
19
+ if (params['success']) this.success = params['success'];
20
+ if (params['authenticity_token']) this.authenticity_token = params['authenticity_token'];
19
21
 
20
22
  var m = this.model;
21
23
  $.each(params['attributes'], function(i, attrib) {
@@ -35,6 +37,7 @@ ModelBinder.prototype = {
35
37
  else if (attrib.type == 'select') control = new BoundSelect(opts);
36
38
  else if (attrib.type == 'checkbox') control = new BoundCheckbox(opts);
37
39
  else if (attrib.type == 'textarea') control = new BoundTextarea(opts);
40
+ else if (attrib.type == 'image') control = new BoundImage(opts);
38
41
 
39
42
  this2.controls.push();
40
43
  });
@@ -4,7 +4,7 @@ module Caboose
4
4
 
5
5
  # GET /admin
6
6
  def index
7
- return if !user_is_allowed('admin', 'view')
7
+
8
8
  end
9
9
 
10
10
  # GET /station
@@ -4,7 +4,8 @@ module Caboose
4
4
 
5
5
  # GET /login
6
6
  def index
7
- @return_url = params[:return_url].nil? ? "/" : params[:return_url];
7
+ @return_url = params[:return_url].nil? ? "/" : params[:return_url]
8
+ @modal = params[:modal].nil? ? false : params[:modal]
8
9
  redirect_to @return_url if logged_in?
9
10
  end
10
11
 
@@ -1 +1,38 @@
1
1
  <h1>Admin</h1>
2
+
3
+ <%= content_for :caboose_js do %>
4
+ <script type='text/javascript'>
5
+
6
+ $(document).ready(function() {
7
+ open_colorbox();
8
+ });
9
+
10
+ function open_colorbox() {
11
+ $.colorbox({
12
+ href: '/login?modal=1&return_url=/station',
13
+ iframe: true,
14
+ innerWidth: 200,
15
+ innerHeight: 50,
16
+ scrolling: false,
17
+ transition: 'fade',
18
+ closeButton: false,
19
+ onComplete: fix_colorbox,
20
+ opacity: 0.50,
21
+ onClosed: function() { open_colorbox(); }
22
+ });
23
+ }
24
+
25
+ function fix_colorbox() {
26
+ $("#cboxTopLeft" ).css('background', '#111');
27
+ $("#cboxTopRight" ).css('background', '#111');
28
+ $("#cboxBottomLeft" ).css('background', '#111');
29
+ $("#cboxBottomRight" ).css('background', '#111');
30
+ $("#cboxMiddleLeft" ).css('background', '#111');
31
+ $("#cboxMiddleRight" ).css('background', '#111');
32
+ $("#cboxTopCenter" ).css('background', '#111');
33
+ $("#cboxBottomCenter" ).css('background', '#111');
34
+ $("#cboxClose" ).hide();
35
+ }
36
+
37
+ </script>
38
+ <% end %>
@@ -28,7 +28,7 @@ function login()
28
28
  if (resp.error)
29
29
  modal.autosize("<p class='note error'>" + resp.error + "</p>");
30
30
  else if (resp.redirect != false)
31
- parent.window.location = resp.redirect;
31
+ <%= @modal ? "" : "parent." %>window.location = resp.redirect;
32
32
  else
33
33
  parent.location.reload(true);
34
34
  },
@@ -1,6 +1,7 @@
1
1
 
2
2
  <div id='top_nav'>
3
3
  <div class='caboose_logo'></div>
4
+ <!--
4
5
  <ul>
5
6
  <% if (@user.nil? || @user == Caboose::User.logged_out_user) %>
6
7
  <li><a href='/login?return_url=#{request.fullpath}' id='caboose_login'><span>Login</span></a></li>
@@ -9,4 +10,5 @@
9
10
  <li class='cpanel' ><a href='/station' id='caboose_station'><span>Dashboard</span></a></li>
10
11
  <% end %>
11
12
  </ul>
13
+ -->
12
14
  </div>
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-10 00:00:00.000000000 Z
12
+ date: 2013-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -179,6 +179,7 @@ files:
179
179
  - app/assets/javascripts/caboose/model/bound_checkbox.js
180
180
  - app/assets/javascripts/caboose/model/bound_checkbox_multiple.js
181
181
  - app/assets/javascripts/caboose/model/bound_control.js
182
+ - app/assets/javascripts/caboose/model/bound_image.js
182
183
  - app/assets/javascripts/caboose/model/bound_select.js
183
184
  - app/assets/javascripts/caboose/model/bound_text.js
184
185
  - app/assets/javascripts/caboose/model/bound_textarea.js