classiccms 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,8 +95,8 @@ module Classiccms
95
95
  image.file.name = params[:Filedata][:filename]
96
96
  if !image.save
97
97
  file = Document.new
98
- file.file = params[:Filedata][:tempfile].read
99
- file.file.name = params[:Filedata][:filename]
98
+ file.file = image.file.data
99
+ file.file.name = image.file.name
100
100
  file.save
101
101
  end
102
102
 
@@ -107,7 +107,6 @@ module Classiccms
107
107
  end
108
108
  post '/file/destroy' do
109
109
  image = Image.where(:id => params[:id]).first
110
- p image
111
110
  if image != nil
112
111
  image.destroy
113
112
  else
@@ -41,6 +41,42 @@ class ImageType
41
41
  end
42
42
  end
43
43
  end
44
+ class DocumentType
45
+ attr_reader :document_id
46
+
47
+ def initialize(document_id)
48
+ @document_id
49
+ end
50
+
51
+ class << self
52
+
53
+ # Get the object as it was stored in the database, and instantiate
54
+ # this custom class from it.
55
+ def demongoize(object_id)
56
+ document = Document.where(:id => object_id).first
57
+ if document != nil
58
+ document.file
59
+ else
60
+ Dragonfly[:file].fetch_file(File.join(Dir.pwd, 'public/not_found.jpeg'))
61
+ end
62
+ end
63
+
64
+ # Takes any possible object and converts it to how it would be
65
+ # stored in the database.
66
+ def mongoize(object_id)
67
+ object_id
68
+ end
69
+
70
+ # Converts the object that was supplied to a criteria and converts it
71
+ # into a database friendly form.
72
+ def evolve(object)
73
+ case object
74
+ when FileType then object.mongoize
75
+ else object
76
+ end
77
+ end
78
+ end
79
+ end
44
80
 
45
81
  class Base
46
82
  include Mongoid::Document
@@ -2,18 +2,17 @@
2
2
  $ ->
3
3
  new Browser
4
4
 
5
-
6
-
7
5
  class Browser
8
6
  constructor: ->
9
7
  @input = $('#input').first().val()
8
+ @type = $('#type').first().val()
9
+
10
10
  @p =
11
11
  images: '.images'
12
12
  image: 'img'
13
13
  destroy: '.destroy'
14
14
  button: '#file_upload'
15
15
  @listen()
16
-
17
16
  listen: ->
18
17
  $('#edit_bg').slideDown()
19
18
  @set_upload_button()
@@ -24,6 +23,7 @@ class Browser
24
23
 
25
24
  add_tooltip: ->
26
25
  $('[rel=tooltip]').tooltip();
26
+
27
27
  change_window: (id)->
28
28
  console.log id
29
29
  $('.menu li').removeClass('active')
@@ -37,12 +37,15 @@ class Browser
37
37
  select: () ->
38
38
  $('.item').click (event)=>
39
39
  url = $(event.currentTarget).attr('url')
40
- input = $('input[name=return]').first().val()
41
- if input.length > 0
42
- window.opener.CKEDITOR.tools.callFunction(input, url)
40
+ ckeditor = $('input[name=return]').first().val()
41
+ if ckeditor.length > 0
42
+ window.opener.CKEDITOR.tools.callFunction(ckeditor, url)
43
+ else if @type == 'document'
44
+ window.opener.$j('#' + @input).first().val($(event.currentTarget).attr('id'))
45
+ window.opener.$j('#' + @input + '_preview').empty().append($(event.currentTarget).attr('name'))
43
46
  else
44
- window.opener.$('#' + @input).first().val($(event.currentTarget).attr('id'))
45
- window.opener.$("##{@input}_preview img").attr('src', $(event.currentTarget).attr('src'))
47
+ window.opener.$j('#' + @input).first().val($(event.currentTarget).attr('id'))
48
+ window.opener.$j('#' + @input + '_preview img').attr('src', $(event.currentTarget).attr('src'))
46
49
  self.close()
47
50
 
48
51
  destroy: () ->
@@ -35,57 +35,13 @@ class Sort
35
35
  $j.post '/cms/sort', {section: section, order: order}
36
36
  }
37
37
 
38
- class Image
39
- #needs a rewrite
38
+ class Image
40
39
  constructor: (input) ->
41
- @input = input
42
- @p =
43
- images: '#iki #edit_bg .images'
44
- image: '#iki #edit_bg .images .image img'
45
- destroy: '#iki #edit_bg .images .image .destroy'
46
- button: '#iki #file_upload'
47
-
48
- window.open('/cms/ckeditor/files?input='+$(@input).attr('id'),'upload','width=960,height=750,left=200,top=100,screenX=200,screenY=100')
49
- @listen()
40
+ window.open('/cms/ckeditor/files?input='+$(input).attr('id')+'&type=image','upload','width=960,height=750,left=200,top=100,screenX=200,screenY=100')
50
41
 
51
- listen: ->
52
- #$j('#edit_bg').slideUp()
53
- #$j.get '/cms/images', (data) =>
54
- # @form = $j('#edit_bg')
55
- # $j('#edit_bg').after(data)
56
- # @set_upload_button()
57
- # $j('#' + @input.val()).addClass('selected')
58
- # @select()
59
- # @destroy()
60
-
61
- destroy: () ->
62
- $j(@p.images + ' .image').live 'mouseover mouseout', (event) =>
63
- if (event.type == 'mouseover')
64
- $j(event.currentTarget).find('.destroy').show()
65
- else
66
- $j(event.currentTarget).find('.destroy').hide()
67
- $j(@p.destroy).click (event) =>
68
- id = $j(event.currentTarget).parent().attr('id')
69
- $j('.images').find('#' + id).hide()
70
- $j.post '/cms/image/destroy', {id: id}
71
-
72
- select: () ->
73
- $j(@p.image).click (event) =>
74
- $j(@p.image).parent().removeClass('selected')
75
- $j(event.currentTarget).parent().addClass('selected')
76
- $j(@input).val($j(event.currentTarget).parent().attr('id'))
77
- $j('#edit_bg.popup').slideUp()
78
- @form.slideDown()
79
-
80
- set_upload_button: ->
81
- if($j('#file_upload').length != 0)
82
- $j('#file_upload').uploadify
83
- 'swf' : '/cms/js/uploadify/uploadify.swf'
84
- 'uploader' : '/cms/upload/image'
85
- 'onUploadSuccess' : (file, data, response) =>
86
- $j(data).replaceAll(@p.images)
87
- @select()
88
- @destroy()
42
+ class Document
43
+ constructor: (input) ->
44
+ window.open('/cms/ckeditor/files?input='+$(input).attr('id')+'&type=document','upload','width=960,height=750,left=200,top=100,screenX=200,screenY=100')
89
45
 
90
46
 
91
47
  class TopPanel
@@ -103,6 +59,7 @@ class TopPanel
103
59
  destroy: '#iki #edit_box #edit_bottom_nav .delete'
104
60
  destroy_label: '#iki .delete_item'
105
61
  image_select: '#iki .image_select'
62
+ document_select: '#iki .document_select'
106
63
 
107
64
  @listen()
108
65
  @show()
@@ -113,6 +70,7 @@ class TopPanel
113
70
  $j(@p.create).click => @create('/cms/save')
114
71
  $j(@p.destroy).click (event) => @destroy('/cms/destroy', $j(event.target).attr('id'))
115
72
  $j(@p.image_select).click => new Image($j(event.target).next())
73
+ $j(@p.document_select).click => new Document($j(event.target).next())
116
74
  @delete_button_hover()
117
75
 
118
76
  menu_switch: (object) ->
@@ -172,7 +130,7 @@ class TopPanel
172
130
  class Editor
173
131
  constructor: ->
174
132
  @p =
175
- textarea: '#edit_box textarea'
133
+ textarea: '#iki textarea'
176
134
  buttons: '#iki .cke_button a'
177
135
  config: {
178
136
  skin : 'kama',
@@ -203,6 +161,7 @@ class Editor
203
161
  $j(this).attr('title', title)
204
162
  add: ->
205
163
  $j(@p.textarea).each (index, element) =>
164
+ console.log 'wooh woop'
206
165
  $j(element).ckeditor(@p.config)
207
166
  @hover()
208
167
  remove: ->
@@ -1,3 +1,3 @@
1
1
  module Classiccms #:nodoc
2
- VERSION = "0.6.4"
2
+ VERSION = "0.6.5"
3
3
  end
@@ -14,6 +14,7 @@
14
14
  /%link{:rel=>'stylesheet', :href=>'/cms/css/images.css', :type=> 'text/css'}
15
15
  %body#iki
16
16
  %input{:type => 'hidden', :id => 'input', :value => params[:input]}
17
+ %input{:type => 'hidden', :id => 'type', :value => params[:type]}
17
18
  .container{:style => 'margin-top: 20px'}
18
19
  .row
19
20
  .span4
@@ -7,8 +7,8 @@
7
7
  %th Grootte
8
8
  %tbody
9
9
  - Document.all.each do |document|
10
- %tr.item{:id => document.id, :url => document.file.url}
11
- %td= document.file.name
10
+ %tr{:id => document.id}
11
+ %td.name.item{:id => document.id, :url => document.file.url, :name => document.file.name}= document.file.name
12
12
  %td= document.created_at.strftime('%d-%m-%Y')
13
13
  %td
14
14
  %button.btn.btn-mini.btn-danger.destroy{:style => 'position: absolute;', :type => 'button', :'data-original-title' => 'Verwijder', :rel => 'tooltip', :'data-id' => document.id}
@@ -14,7 +14,7 @@
14
14
  - when 'input'
15
15
  %input{:type=> 'text', :name=> name, :value=> record[key], :class=>"textfield", :type=> "text"}
16
16
  - when 'textarea'
17
- %textarea{:id => key, :name=> name}= record[key]
17
+ %textarea{:id => key+rand(1...100).to_s, :name=> name}= record[key]
18
18
  - when 'date'
19
19
  - record[key] = Date.today if record[key] == nil
20
20
  %select{:name=>"[#{model}][#{key}(3i)]"}
@@ -33,6 +33,10 @@
33
33
 
34
34
  %p{:id => "file_#{key}_preview", :style => 'float:left; clear:left;'}
35
35
  %img{:src => record.send(key).thumb('50x50').url}
36
+ - when 'document'
37
+ %p.document_select Selecteer bestand
38
+ %input{:type => 'hidden', :id => "file_#{key}", :name=> name, :value => record[key]}
39
+ %p{:id => "file_#{key}_preview", :style => 'float:left; clear:left;'}= record.send(key).name
36
40
 
37
41
  - when 'images'
38
42
  - if record.new_record?
@@ -3,4 +3,4 @@
3
3
  .span{:style => 'margin-bottom: 20px;', :id => image.id}
4
4
  %button.btn.btn-mini.btn-danger.destroy{:style => 'position: absolute;', :type => 'button', :'data-original-title' => 'Verwijder', :rel => 'tooltip', :'data-id' => image.id}
5
5
  %i.icon-trash.icon-white
6
- %img.img-rounded.item{:style => 'height: 113px;', :id => image.id, :src => image.file.process(:thumb, '113x113#').url, :url => image.file.url}
6
+ %img.img-rounded.item{:style => 'height: 113px;', :id => image.id, :src => image.file.process(:thumb, '113x113#').url, :url => image.file.url, :name => image.file.name}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classiccms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
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: 2012-10-16 00:00:00.000000000 Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec