effective_bootstrap 0.3.22 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1574a75630924ef8597cd9527a4370ea425fb296
4
- data.tar.gz: 4c63694277e88ef82e1d05f99b2dd350be5cf408
3
+ metadata.gz: b583f66f6d1a4bb7cbb97779f5328740b08b1c1f
4
+ data.tar.gz: bbe3c4203d1b0ff0cdf5cc5b486b7513432953ca
5
5
  SHA512:
6
- metadata.gz: 0d061a258b2aca7adff48050b6038aef9df09294b60e5d336fbb29fa128c0d221518ff53d7a013136a39bb23967434ed4940c8d187253d8e02ffd8a5b919e53d
7
- data.tar.gz: 1ec116b1a8c4b33ff5778c45ec6c23213270be1e3a328a2cf07c18907ebde7e97ffce9caf82506e81aba262bd20560972059d59abd80a8021351a29f02d46187
6
+ metadata.gz: 7cc537b958cf168a041b967bde69d3453a277301f026f50695ee99baa3a1e7c565288ab1356c6b09f1e955cc5a0418525d59c742803356509d79d536140ec57d
7
+ data.tar.gz: f8e1f99e6f71b1e9476d9efe6166e028aa465a29148cd205e82170d4d772ac4e4aa6a85334575a14c7577eb9447ced2ea56bb26205e2d98c5263b0e71f8bf42c
@@ -8,6 +8,7 @@
8
8
  //= require ./effective_time_zone_select/input
9
9
 
10
10
  //= require ./effective_checks/input
11
+ //= require ./effective_ck_editor/input
11
12
  //= require ./effective_editor/input
12
13
  //= require ./effective_file/input
13
14
  //= require ./effective_number_text/input
@@ -0,0 +1,72 @@
1
+ # http://eonasdan.github.io/bootstrap-datetimepicker/Options/
2
+ (this.EffectiveBootstrap || {}).effective_ck_editor = ($element, options) ->
3
+ setupCkeditor($element)
4
+ initCkeditor($element, $element.data('input-js-options'))
5
+
6
+ # This is a one-time initialization that is done to check that all the scripts are properly set up
7
+ setupCkeditor = ($inputs) ->
8
+ return unless $inputs.length > 0
9
+
10
+ input_js_options = $inputs.first().data('input-js-options') || {}
11
+
12
+ ckeditor_present = ((try CKEDITOR.version) || '').length > 0
13
+ $head = $('head')
14
+
15
+ unless ckeditor_present
16
+ $head.append("<link href='#{input_js_options['effective_ckeditor_css_path']}' type='text/css', media='screen' rel='stylesheet' />")
17
+ jQuery.ajax({url: input_js_options['effective_ckeditor_js_path'], dataType: 'script', cache: true, async: false})
18
+
19
+ initCkeditor = ($element, input_options) ->
20
+ options =
21
+ toolbar: (input_options['toolbar'] || 'full')
22
+ effectiveRegionType: 'full'
23
+ customConfig: ''
24
+ enterMode: CKEDITOR.ENTER_P
25
+ shiftEnterMode: CKEDITOR.ENTER_BR
26
+ startupOutlineBlocks: true
27
+ startupShowBorders: true
28
+ disableNativeTableHandles: true
29
+ disableNativeSpellChecker: false
30
+ extraPlugins: 'effective_regions,effective_assets'
31
+ removePlugins: 'elementspath'
32
+ format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;div'
33
+ templates: 'effective_regions'
34
+ templates_files: []
35
+ templates_replaceContent: false
36
+ filebrowserWindowHeight: 600
37
+ filebrowserWindowWidth: 800
38
+ filebrowserBrowseUrl: window.CKEDITOR_FILE_BROWSE_URL
39
+ filebrowserImageBrowseUrl: window.CKEDITOR_FILE_BROWSE_URL + '?only=images'
40
+ toolbar_full: [
41
+ { name: 'html', items: ['Sourcedialog', '-', 'ShowBlocks'] },
42
+ { name: 'editing', items: ['Undo', 'Redo'] },
43
+ { name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'] },
44
+ { name: 'justify', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight']},
45
+ { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] },
46
+ { name: 'lists', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent'] },
47
+ '/'
48
+ { name: 'definedstyles', items: ['Styles', 'Format'] },
49
+ { name: 'links', items: ['Link', 'Unlink', '-', 'Anchor'] },
50
+ { name: 'insert', items: ['Image', 'oembed'] },
51
+ { name: 'lists', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent'] },
52
+ { name: 'insert2', items: ['Table', 'EffectiveReferences', 'Blockquote', 'HorizontalRule', 'PageBreak'] },
53
+ { name: 'colors', items: ['TextColor', 'BGColor'] },
54
+ { name: 'snippets', items: ['Templates', 'InsertSnippet'] }
55
+ ],
56
+ toolbar_simple: [
57
+ { name: 'definedstyles', items: ['Format'] },
58
+ { name: 'html', items: ['ShowBlocks'] },
59
+ { name: 'justify', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight']}
60
+ { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline'] },
61
+ { name: 'insert', items: ['Link', 'Table'] },
62
+ { name: 'lists', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent'] },
63
+ ]
64
+
65
+ options[k] = v for k, v of ($element.data('input-js-options') || {})
66
+
67
+ ckeditor = CKEDITOR.replace($element.attr('id'), options)
68
+
69
+ ckeditor.on 'insertElement', (event) ->
70
+ element = $(event.data.$)
71
+ if element.is('table')
72
+ element.removeAttr('style').addClass('table')
@@ -0,0 +1 @@
1
+ //= require ./initialize
@@ -15,3 +15,5 @@ $(document).on 'direct-upload:error', (event) ->
15
15
  $(document).on 'direct-upload:end', (event) ->
16
16
  $("[data-direct-upload-id=#{event.detail.id}]").addClass('direct-upload--complete')
17
17
 
18
+ $(document).on 'change', "input[type='file'][data-click-submit]", (event) ->
19
+ $(event.currentTarget).closest('form').find('button[type=submit],input[type=submit]').first().click()
@@ -1,5 +1,4 @@
1
- .direct-uploads {
2
- }
1
+ .direct-uploads {}
3
2
 
4
3
  .direct-upload {
5
4
  display: inline-block;
@@ -12,8 +11,8 @@
12
11
  line-height: 13px;
13
12
  }
14
13
 
15
- .direct-upload--pending {
16
- opacity: 0.6;
14
+ .direct-upload--pending {
15
+ opacity: 0.6;
17
16
  }
18
17
 
19
18
  .direct-upload__progress {
@@ -38,3 +37,8 @@
38
37
  input[type=file][data-direct-upload-url][disabled] {
39
38
  display: none;
40
39
  }
40
+
41
+ // Attachments
42
+ table.effective_file_attachments {
43
+ img { max-width: 128px; max-height: 128px;}
44
+ }
@@ -34,6 +34,10 @@ module Effective
34
34
  Effective::FormInputs::Checks.new(name, options, builder: self).to_html
35
35
  end
36
36
 
37
+ def ck_editor(name, options = {}, &block)
38
+ Effective::FormInputs::CkEditor.new(name, options, builder: self).to_html(&block)
39
+ end
40
+
37
41
  def date_field(name, options = {})
38
42
  Effective::FormInputs::DateField.new(name, options, builder: self).to_html { super(name, options) }
39
43
  end
@@ -7,7 +7,7 @@ module Effective
7
7
  EXCLUSIVE_CLASS_SUFFIXES = ['-primary', '-secondary', '-success', '-danger', '-warning', '-info', '-light', '-dark']
8
8
 
9
9
  delegate :object, to: :@builder
10
- delegate :capture, :content_tag, :link_to, :icon, to: :@template
10
+ delegate :capture, :content_tag, :link_to, :icon, :asset_path, to: :@template
11
11
 
12
12
  # So this takes in the options for an entire form group.
13
13
  def initialize(name, options, builder:, html_options: nil)
@@ -0,0 +1,48 @@
1
+ module Effective
2
+ module FormInputs
3
+ class CkEditor < Effective::FormInput
4
+
5
+ def build_input(&block)
6
+ content = value.presence || (capture(&block) if block_given?)
7
+ @builder.super_text_area(name, (options[:input] || {}).merge(autocomplete: 'off'))
8
+ end
9
+
10
+ def input_html_options
11
+ { class: 'effective_ck_editor form-control', id: unique_id }
12
+ end
13
+
14
+ def input_js_options
15
+ {
16
+ effective_ckeditor_js_path: asset_path('effective_ckeditor.js'),
17
+ effective_ckeditor_css_path: asset_path('effective_ckeditor.css'),
18
+ contentsCss: contentsCss,
19
+ toolbar: toolbar,
20
+ height: height,
21
+ width: width
22
+ }.compact
23
+ end
24
+
25
+ def contentsCss
26
+ @contents_css ||= case (obj = options.delete(:contentsCss))
27
+ when :bootstrap
28
+ 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css'
29
+ when false then nil
30
+ else obj || asset_path('application.css')
31
+ end
32
+ end
33
+
34
+ def toolbar
35
+ @toolbar ||= (options.delete(:toolbar) || :full)
36
+ end
37
+
38
+ def height
39
+ @height ||= options.delete(:height)
40
+ end
41
+
42
+ def width
43
+ @width ||= options.delete(:width)
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -3,7 +3,14 @@ module Effective
3
3
  class FileField < Effective::FormInput
4
4
 
5
5
  def build_input(&block)
6
- build_attachments + build_uploads + super
6
+ case attachments_style
7
+ when :card
8
+ build_attachments + build_uploads + super
9
+ when :table, :ck_assets
10
+ super + build_uploads + build_attachments
11
+ else
12
+ raise('unsupported attachments_style, try :card or :table')
13
+ end
7
14
  end
8
15
 
9
16
  def input_html_options
@@ -11,8 +18,9 @@ module Effective
11
18
  class: 'form-control form-control-file btn btn-outline-secondary',
12
19
  multiple: multiple?,
13
20
  direct_upload: true,
14
- 'data-progress-template': progress_template
15
- }
21
+ 'data-progress-template': progress_template,
22
+ 'data-click-submit': (true if click_submit?),
23
+ }.compact
16
24
  end
17
25
 
18
26
  def multiple?
@@ -24,10 +32,63 @@ module Effective
24
32
 
25
33
  attachments = object.send(name).respond_to?(:length) ? object.send(name) : [object.send(name)]
26
34
 
27
- content_tag(:div, attachments.map { |attachment| build_attachment(attachment) }.join.html_safe, class: 'attachments row')
35
+ case attachments_style
36
+ when :card
37
+ build_card_attachments(attachments)
38
+ when :table, :ck_assets
39
+ build_table_attachments(attachments)
40
+ else
41
+ raise('unsupported attachments_style, try :card or :table')
42
+ end
43
+ end
44
+
45
+ def build_table_attachments(attachments)
46
+ content_tag(:table, class: 'table table-hover effective_file_attachments') do
47
+ content_tag(:thead) do
48
+ content_tag(:tr) do
49
+ content_tag(:th, 'Image') +
50
+ content_tag(:th, 'Title') +
51
+ content_tag(:th, 'Size') +
52
+ content_tag(:th, '')
53
+ end
54
+ end +
55
+ content_tag(:tbody) do
56
+ attachments.map { |attachment| content_tag(:tr, build_table_attachment(attachment)) }.join.html_safe
57
+ end
58
+ end
59
+ end
60
+
61
+ def build_table_attachment(attachment)
62
+ url = (@template.url_for(attachment) rescue false)
63
+ return unless url
64
+
65
+ content_tag(:td) do
66
+ if attachment.image?
67
+ content_tag(:img, '', class: '', src: url, alt: attachment.filename.to_s)
68
+ end
69
+ end +
70
+
71
+ content_tag(:td, link_to(attachment.filename, url)) +
72
+ content_tag(:td, (attachment.content_type + '<br>' + @template.number_to_human_size(attachment.byte_size)).html_safe) +
73
+
74
+ content_tag(:td) do
75
+ if attachments_style == :ck_assets
76
+ content = if attachment.image?
77
+ content_tag(:img, '', class: '', src: url, alt: attachment.filename.to_s)
78
+ else
79
+ link_to(attachment.filename, url)
80
+ end
81
+
82
+ link_to('Attach', url, class: 'btn btn-primary', 'data-effective-file-insert-ck-asset': true, 'data-asset': content, 'data-asset-id': 3)
83
+ end
84
+ end
85
+ end
86
+
87
+ def build_card_attachments(attachments)
88
+ content_tag(:div, attachments.map { |attachment| build_card_attachment(attachment) }.join.html_safe, class: 'effective_file_attachments row')
28
89
  end
29
90
 
30
- def build_attachment(attachment)
91
+ def build_card_attachment(attachment)
31
92
  url = (@template.url_for(attachment) rescue false)
32
93
  return unless url
33
94
 
@@ -63,6 +124,15 @@ module Effective
63
124
  end
64
125
  end
65
126
 
127
+ def click_submit?
128
+ return @click_submit unless @click_submit.nil?
129
+ @click_submit ||= (options.delete(:click_submit) || false)
130
+ end
131
+
132
+ def attachments_style
133
+ @attachments_style ||= (options[:input].delete(:attachments_style) || options[:input].delete(:attachment_style) || :card)
134
+ end
135
+
66
136
  end
67
137
  end
68
138
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.3.22'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.22
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-02 00:00:00.000000000 Z
11
+ date: 2019-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -375,6 +375,8 @@ files:
375
375
  - app/assets/javascripts/effective_bootstrap/logic.js.coffee
376
376
  - app/assets/javascripts/effective_checks/initialize.js.coffee
377
377
  - app/assets/javascripts/effective_checks/input.js
378
+ - app/assets/javascripts/effective_ck_editor/initialize.js.coffee
379
+ - app/assets/javascripts/effective_ck_editor/input.js
378
380
  - app/assets/javascripts/effective_date/initialize.js.coffee
379
381
  - app/assets/javascripts/effective_date/input.js
380
382
  - app/assets/javascripts/effective_datetime/bootstrap-datetimepicker.js
@@ -439,6 +441,7 @@ files:
439
441
  - app/models/effective/form_input.rb
440
442
  - app/models/effective/form_inputs/check_box.rb
441
443
  - app/models/effective/form_inputs/checks.rb
444
+ - app/models/effective/form_inputs/ck_editor.rb
442
445
  - app/models/effective/form_inputs/collection_input.rb
443
446
  - app/models/effective/form_inputs/date_field.rb
444
447
  - app/models/effective/form_inputs/datetime_field.rb