rails_admin_featured_content 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +5 -0
  7. data/CODE_OF_CONDUCT.md +49 -0
  8. data/Gemfile +13 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +81 -0
  11. data/Rakefile +21 -0
  12. data/app/assets/images/fc-image-default.jpg +0 -0
  13. data/app/assets/images/fc-loading.svg +1 -0
  14. data/app/assets/images/fc-snippet-highlight.jpg +0 -0
  15. data/app/assets/images/fc-snippet-slide.jpg +0 -0
  16. data/app/assets/images/fc-snippet-text.jpg +0 -0
  17. data/app/assets/images/fc-snippet-three.jpg +0 -0
  18. data/app/assets/images/fc-snippet-two.jpg +0 -0
  19. data/app/assets/javascripts/rails_admin/featured_content.js.erb +399 -0
  20. data/app/assets/stylesheets/rails_admin/featured_content.scss +599 -0
  21. data/app/controllers/rails_admin_featured_content/featured_content_controller.rb +28 -0
  22. data/app/models/.keep +0 -0
  23. data/app/models/rails_admin_featured_content/featured_content.rb +16 -0
  24. data/app/models/rails_admin_featured_content/featured_content_image.rb +9 -0
  25. data/app/views/.gitkeep +0 -0
  26. data/app/views/rails_admin/main/featured_content.html.erb +42 -0
  27. data/bin/console +14 -0
  28. data/bin/setup +8 -0
  29. data/config/initializers/assets.rb +7 -0
  30. data/config/locales/featured_content.en.yml +17 -0
  31. data/config/locales/featured_content.pt-BR.yml +17 -0
  32. data/config/routes.rb +9 -0
  33. data/lib/generators/rails_admin_featured_content_generator.rb +31 -0
  34. data/lib/generators/templates/create_featured_content_images_migration.rb +10 -0
  35. data/lib/generators/templates/create_featured_content_migration.rb +11 -0
  36. data/lib/generators/templates/featured_content_image_uploader.rb +50 -0
  37. data/lib/generators/templates/rails_admin_featured_content.rb +22 -0
  38. data/lib/rails_admin_featured_content.rb +55 -0
  39. data/lib/rails_admin_featured_content/engine.rb +23 -0
  40. data/lib/rails_admin_featured_content/version.rb +3 -0
  41. data/rails_admin_featured_content.gemspec +45 -0
  42. data/spec/controllers/rails_admin_featured_content/featured_content_controller_spec.rb +42 -0
  43. data/spec/dummy/Gemfile +11 -0
  44. data/spec/dummy/Gemfile.lock +235 -0
  45. data/spec/dummy/Rakefile +6 -0
  46. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  47. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  48. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  49. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  50. data/spec/dummy/app/uploaders/content_builder_image_uploader.rb +54 -0
  51. data/spec/dummy/app/uploaders/featured_content_image_uploader.rb +50 -0
  52. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  53. data/spec/dummy/bin/bundle +3 -0
  54. data/spec/dummy/bin/rails +4 -0
  55. data/spec/dummy/bin/rake +4 -0
  56. data/spec/dummy/bin/setup +29 -0
  57. data/spec/dummy/config.ru +4 -0
  58. data/spec/dummy/config/application.rb +31 -0
  59. data/spec/dummy/config/boot.rb +5 -0
  60. data/spec/dummy/config/database.yml +25 -0
  61. data/spec/dummy/config/environment.rb +5 -0
  62. data/spec/dummy/config/environments/development.rb +41 -0
  63. data/spec/dummy/config/environments/production.rb +79 -0
  64. data/spec/dummy/config/environments/test.rb +42 -0
  65. data/spec/dummy/config/initializers/assets.rb +11 -0
  66. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  67. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  68. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  69. data/spec/dummy/config/initializers/inflections.rb +16 -0
  70. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  71. data/spec/dummy/config/initializers/rails_admin.rb +37 -0
  72. data/spec/dummy/config/initializers/rails_admin_content_builder.rb +37 -0
  73. data/spec/dummy/config/initializers/rails_admin_featured_content.rb +22 -0
  74. data/spec/dummy/config/initializers/session_store.rb +3 -0
  75. data/spec/dummy/config/initializers/simple_form.rb +165 -0
  76. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  77. data/spec/dummy/config/locales/en.yml +23 -0
  78. data/spec/dummy/config/locales/simple_form.en.yml +31 -0
  79. data/spec/dummy/config/routes.rb +57 -0
  80. data/spec/dummy/config/secrets.yml +22 -0
  81. data/spec/dummy/db/development.sqlite3 +0 -0
  82. data/spec/dummy/db/migrate/20160729105801_create_content_builder_categories.rb +10 -0
  83. data/spec/dummy/db/migrate/20160729105802_create_content_builders.rb +16 -0
  84. data/spec/dummy/db/migrate/20160729105803_create_content_builder_images.rb +10 -0
  85. data/spec/dummy/db/migrate/20160729105947_create_featured_contents.rb +11 -0
  86. data/spec/dummy/db/migrate/20160729105948_create_featured_content_images.rb +10 -0
  87. data/spec/dummy/db/schema.rb +64 -0
  88. data/spec/dummy/db/test.sqlite3 +0 -0
  89. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  90. data/spec/dummy/log/development.log +1698 -0
  91. data/spec/dummy/log/test.log +36 -0
  92. data/spec/dummy/public/404.html +67 -0
  93. data/spec/dummy/public/422.html +67 -0
  94. data/spec/dummy/public/500.html +66 -0
  95. data/spec/dummy/public/favicon.ico +0 -0
  96. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/1/center_example.jpg +0 -0
  97. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/1/example.jpg +0 -0
  98. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/1/left_or_right_example.jpg +0 -0
  99. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/2/center_example.jpg +0 -0
  100. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/2/example.jpg +0 -0
  101. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/2/left_or_right_example.jpg +0 -0
  102. data/spec/dummy/public/uploads/rails_admin_featured_content/featured_content_image/image/1/example.jpg +0 -0
  103. data/spec/dummy/public/uploads/rails_admin_featured_content/featured_content_image/image/1/thumb_example.jpg +0 -0
  104. data/spec/dummy/public/uploads/tmp/1461693110-14578-0001-7683/center_example.jpg +0 -0
  105. data/spec/dummy/public/uploads/tmp/1461693110-14578-0001-7683/example.jpg +0 -0
  106. data/spec/dummy/public/uploads/tmp/1461693110-14578-0001-7683/left_or_right_example.jpg +0 -0
  107. data/spec/dummy/public/uploads/tmp/1461693202-14651-0001-6505/center_example.jpg +0 -0
  108. data/spec/dummy/public/uploads/tmp/1461693202-14651-0001-6505/example.jpg +0 -0
  109. data/spec/dummy/public/uploads/tmp/1461693202-14651-0001-6505/left_or_right_example.jpg +0 -0
  110. data/spec/dummy/public/uploads/tmp/1461693245-14728-0001-4392/center_example.jpg +0 -0
  111. data/spec/dummy/public/uploads/tmp/1461693245-14728-0001-4392/example.jpg +0 -0
  112. data/spec/dummy/public/uploads/tmp/1461693245-14728-0001-4392/left_or_right_example.jpg +0 -0
  113. data/spec/factories/featured_content.rb +7 -0
  114. data/spec/factories/featured_content_image.rb +7 -0
  115. data/spec/fixtures/assets/example.jpg +0 -0
  116. data/spec/spec_helper.rb +20 -0
  117. data/spec/version_spec.rb +7 -0
  118. data/vendor/assets/stylesheets/rails_admin_featured_content.scss +557 -0
  119. metadata +575 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2be80d5e00f63e2d5d457b9abe58bc1b873b423
4
+ data.tar.gz: 693c9c0d737be40254ce57be23d5ae7e6c6f1fca
5
+ SHA512:
6
+ metadata.gz: df07ac02eeec2398678a69ea7f48b91e97724e629c55595a8792abce2fe917d91311f34dd567ff92370b0ee2651f49e79eb5c885d5765d7bb9ce58ee779e7808
7
+ data.tar.gz: d5554e31feedf50b2eca3910e6f336f46e1de013bdd27c6215face2b932091c94ede79a9514cf7c450bfee2ceab766ed5c143cef6703c2418fb13f411b678ebd
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/*
11
+ /test_app/*
12
+ /spec/dummy/tmp/*
13
+ spec/dummy/log/test.log
14
+ spec/dummy/db/test.sqlite3
15
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rails_admin_feature_content
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at luizpicolo@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'sqlite3'
7
+ gem 'friendly_id'
8
+ gem 'rails_admin'
9
+ gem 'fuubar'
10
+ gem 'codeclimate-test-reporter'
11
+ gem 'rails_admin_content_builder', git: 'git://github.com/luizpicolo/rails_admin_content_builder.git'
12
+ gem 'simplecov', require: false
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Luiz Picolo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # RailsAdminFeaturedContent
2
+
3
+ ![Work in progress](http://messages.hellobits.com/warning.svg?message=Work%20in%20progress)
4
+
5
+ Easy way for create featured contents using rails_admin
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+ This is a complement to the gem rails_admin_content_builder, only works with dependencies lists in requirements and not alone
11
+
12
+ ```ruby
13
+ gem 'rails_admin'
14
+ gem 'rails_admin_content_builder'
15
+ gem 'rails_admin_featured_content'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Run the generator and migrations
23
+
24
+ rails g rails_admin_content_builder
25
+ rake db:migrate
26
+
27
+ Add styles in app/assets/application.scss
28
+
29
+ ```ruby
30
+ *= require rails_admin_featured_content
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ Include in your controller
36
+
37
+ ```ruby
38
+ @featured = RailsAdminFeaturedContent::FeaturedContent.where(status: true).first
39
+ ```
40
+
41
+ In your show featured content view
42
+
43
+ ```ruby
44
+ <%= @featured.featured_sanitized %>
45
+ ```
46
+
47
+ ## Requirements
48
+
49
+ Dependencies
50
+
51
+ MiniMagick
52
+ rails_admin
53
+ rails_admin_content_builder
54
+
55
+ Supported ORM
56
+
57
+ ActiveRecord
58
+
59
+ Supported Asset Plugin
60
+
61
+ CarrierWave
62
+
63
+
64
+ ## Usage
65
+
66
+ TODO: Write usage instructions here
67
+
68
+ ## Development
69
+
70
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
71
+
72
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/luizpicolo/rails_admin_featured_content. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
77
+
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
9
+ load 'rails/tasks/engine.rake'
10
+
11
+ Bundler::GemHelper.install_tasks
12
+
13
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
14
+
15
+ require 'rspec/core'
16
+ require 'rspec/core/rake_task'
17
+
18
+ desc "Run all specs in spec directory (excluding plugin specs)"
19
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
20
+
21
+ task :default => :spec
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8"?><svg width='50px' height='50px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-ripple"><rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect><g> <animate attributeName="opacity" dur="2s" repeatCount="indefinite" begin="0s" keyTimes="0;0.33;1" values="1;1;0"></animate><circle cx="50" cy="50" r="40" stroke="#aaaaab" fill="none" stroke-width="6" stroke-linecap="round"><animate attributeName="r" dur="2s" repeatCount="indefinite" begin="0s" keyTimes="0;0.33;1" values="0;22;44"></animate></circle></g><g><animate attributeName="opacity" dur="2s" repeatCount="indefinite" begin="1s" keyTimes="0;0.33;1" values="1;1;0"></animate><circle cx="50" cy="50" r="40" stroke="#7d7d7d" fill="none" stroke-width="6" stroke-linecap="round"><animate attributeName="r" dur="2s" repeatCount="indefinite" begin="1s" keyTimes="0;0.33;1" values="0;22;44"></animate></circle></g></svg>
@@ -0,0 +1,399 @@
1
+ //= require owl.carousel
2
+
3
+ // when rails admin ready
4
+ $(document).on('rails_admin.dom_ready', function() {
5
+ $('.fc-container').sortable({
6
+ revert: true,
7
+ placeholder: 'ui-sortable-placeholder',
8
+ handle: '.fc-tools__btn--move',
9
+ cursor: 'move',
10
+ });
11
+
12
+ $('.fc-item').each(function() {
13
+ autocomplete($(this).attr('id'));
14
+ addEventToInputFile($(this).attr('id'));
15
+ });
16
+
17
+ $('.fc-tools__input--upload').each(function() {
18
+ addEventToInputFile($(this).attr('id'));
19
+ });
20
+
21
+ $('.fc-form').on('submit', function(e) {
22
+ slideDestroy($('.fc-slide'));
23
+
24
+ var content = $('.fc-container').html();
25
+ $('#content').attr('value', content);
26
+ });
27
+
28
+ editable();
29
+ slideActive($('.fc-slide'));
30
+ });
31
+
32
+ // when click on tools buttons
33
+ $(document).on('click', '.fc-tools__btn', function(e) {
34
+ e.preventDefault();
35
+ });
36
+
37
+ // when click on upload button
38
+ $(document).on('click', '.fc-tools__btn--upload', function() {
39
+ $($(this).attr('href')).find('input').trigger('click');
40
+ });
41
+
42
+ // when click on slide add button
43
+ $(document).on('click', '.fc-tools__btn--slide-add', function(e) {
44
+ slideAdd($(this).data('row'), $(this));
45
+ });
46
+
47
+ // when click on slide remove button
48
+ $(document).on('click', '.fc-tools__btn--slide-remove', function(e) {
49
+ var resp = confirm('<%= I18n.t('admin.actions.featured_content.delete_block')%>');
50
+
51
+ if(resp) {
52
+ slideRemove($(this).data('row'), $(this));
53
+ }
54
+ });
55
+
56
+ // when click on delete button
57
+ $(document).on('click', '.fc-tools__btn--delete', function() {
58
+ var resp = confirm('<%= I18n.t('admin.actions.featured_content.delete_block')%>');
59
+
60
+ if(resp) {
61
+ $($(this).attr('href')).remove();
62
+ }
63
+ });
64
+
65
+ // when click on snippet buttons
66
+ $(document).on('click', '.fc-snippet__btn', function(e) {
67
+ e.preventDefault();
68
+
69
+ var snippet = $(this).attr('data-snippet');
70
+ var container = $('.fc-container');
71
+ var row_id = generateID();
72
+ var section_id = generateID();
73
+
74
+ switch (snippet) {
75
+ case '1':
76
+ var element = '<div id="'+ row_id +'" class="fc-row">';
77
+ element += '<div class="fc-tools">';
78
+ element += '<a class="fc-tools__btn fc-tools__btn--move fa fa-arrows" href="#"></a>';
79
+ element += '<a class="fc-tools__btn fc-tools__btn--delete fa fa-trash" href="#'+ row_id + '"></a>';
80
+ element += '</div>';
81
+
82
+ element += '<section id="'+ section_id +'" class="fc-item fc-item--border">';
83
+ element += '<input class="fc-search" type="text" name="search" placeholder="Buscar notícia">';
84
+ element += '<a href="#" class="fc-link fc-link--absolute"></a>';
85
+ element += '<h1 class="fc-title fc-title--highlight"></h1>';
86
+ element += '</section>';
87
+ element += '</div>';
88
+
89
+ container.append(element);
90
+ autocomplete(section_id);
91
+ scrollTo(row_id);
92
+ break;
93
+
94
+ case '2':
95
+ var element = '<div id="'+ row_id +'" class="fc-row">';
96
+ element += '<div class="fc-tools">';
97
+ element += '<a class="fc-tools__btn fc-tools__btn--move fa fa-arrows" href="#"></a>';
98
+ element += '<a class="fc-tools__btn fc-tools__btn--delete fa fa-trash" href="#'+ row_id +'"></a>';
99
+ element += '</div>';
100
+
101
+ element += '<section id="'+ section_id +'" class="fc-item fc-item--border">';
102
+ element += '<a href="#" class="fc-link fc-link--absolute"></a>';
103
+ element += '<input class="fc-search" type="text" name="search" placeholder="Buscar notícia">';
104
+ element += '<h1 class="fc-title fc-title--large"></h1>';
105
+ element += '<p class="fc-text"></p>';
106
+ element += '</section>';
107
+ element += '</div>';
108
+
109
+ container.append(element);
110
+ autocomplete(section_id);
111
+ scrollTo(row_id);
112
+ break;
113
+
114
+ case '3':
115
+ var sections = [];
116
+
117
+ var element = '<div id="'+ row_id +'" class="fc-row">';
118
+ element += '<div class="fc-tools">';
119
+ element += '<a class="fc-tools__btn fc-tools__btn--move fa fa-arrows" href="#"></a>';
120
+ element += '<a class="fc-tools__btn fc-tools__btn--delete fa fa-trash" href="#'+ row_id +'"></a>';
121
+ element += '</div>';
122
+
123
+ element += '<div class="fc-item fc-item--border">';
124
+ element += '<div class="fc-slide">';
125
+ element += '<div class="fc-item fc-slide__owl" id="'+ section_id +'">';
126
+ element += '<input class="fc-search" type="text" name="search" placeholder="Buscar notícia">';
127
+ element += '<div class="fc-slide__item">';
128
+ element += '<div class="fc-tools fc-tools--center">';
129
+ element += '<a class="fc-tools__btn fc-tools__btn--upload fa fa-camera" href="#'+ section_id + '"></a>';
130
+ element += '<a class="fc-tools__btn fc-tools__btn--slide-add fa fa-plus" data-row="'+ row_id +'" href="#'+ section_id +'"></a>';
131
+ element += '<a class="fc-tools__btn fc-tools__btn--slide-remove fa fa-trash" data-row="'+ row_id +'" href="#'+ section_id +'"></a>';
132
+ element += '</div>';
133
+ element += '<a href="#" class="fc-link fc-slide__link"></a>';
134
+ element += '<h2 class="fc-caption fc-slide__caption"></h2>';
135
+ element += '<figure class="fc-slide__figure">';
136
+ element += '<img class="fc-slide__image" src="<%= image_url('cb-image-default.jpg') %>">';
137
+ element += '<input class="fc-tools__input fc-tools__input--upload" type="file" name="image" id="'+ section_id +'">';
138
+ element += '</figure>';
139
+ element += '<div class="fc-slide__content">';
140
+ element += '<h1 class="fc-title fc-slide__title"></h1>';
141
+ element += '<p class="fc-text fc-slide__text"></p>';
142
+ element += '</div>';
143
+ element += '</section>';
144
+ element += '</div>';
145
+ element += '</div>';
146
+ element += '</div>';
147
+ element += '</div>';
148
+
149
+ container.append(element);
150
+
151
+ autocomplete(section_id);
152
+ addEventToInputFile(section_id);
153
+ scrollTo(row_id);
154
+ slideActive($('.fc-slide'));
155
+ break;
156
+
157
+ case '4':
158
+ var sections = [];
159
+
160
+ var element = '<div id="'+ row_id +'" class="fc-row">';
161
+ element += '<div class="fc-tools">';
162
+ element += '<a class="fc-tools__btn fc-tools__btn--move fa fa-arrows" href="#"></a>';
163
+ element += '<a class="fc-tools__btn fc-tools__btn--delete fa fa-trash" href="#'+ row_id +'"></a>';
164
+ element += '</div>';
165
+
166
+ element += '<div class="fc-row fc-row--flex">';
167
+
168
+ for(var i = 0; i < 3; i++) {
169
+ element += '<section id="'+ section_id +'" class="fc-item fc-item--three fc-item--border">';
170
+ element += '<input class="fc-search" type="text" name="search" placeholder="Buscar notícia">';
171
+ element += '<a href="#" class="fc-link fc-link--absolute"></a>';
172
+ element += '<h2 class="fc-caption"></h2>';
173
+ element += '<figure class="fc-figure fc-figure--block fc-figure--large">';
174
+ element += '<img class="fc-image" src="<%= image_url('cb-image-default.jpg') %>">';
175
+ element += '<input class="fc-tools__input fc-tools__input--upload" type="file" name="image" id="'+ section_id +'">';
176
+ element += '<div class="fc-tools fc-tools--center">';
177
+ element += '<a class="fc-tools__btn fc-tools__btn--upload fa fa-camera" href="#'+ section_id + '"></a>';
178
+ element += '</div>';
179
+ element += '</figure>';
180
+ element += '<h1 class="fc-title fc-title--small"></h1>';
181
+ element += '<p class="fc-text"></p>';
182
+ element += '</section>';
183
+
184
+ sections.push(section_id);
185
+ section_id = generateID();
186
+ }
187
+
188
+ element += '</div>';
189
+ element += '</div>';
190
+
191
+ container.append(element);
192
+
193
+ for(var i = 0; i < sections.length; i++) {
194
+ autocomplete(sections[i]);
195
+ addEventToInputFile(sections[i]);
196
+ }
197
+
198
+ scrollTo(row_id);
199
+ break;
200
+
201
+ case '5':
202
+ var sections = [];
203
+
204
+ var element = '<div id="'+ row_id +'" class="fc-row">';
205
+ element += '<div class="fc-tools">';
206
+ element += '<a class="fc-tools__btn fc-tools__btn--move fa fa-arrows" href="#"></a>';
207
+ element += '<a class="fc-tools__btn fc-tools__btn--delete fa fa-trash" href="#'+ row_id +'"></a>';
208
+ element += '</div>';
209
+
210
+ element += '<div class="fc-row fc-row--flex">';
211
+
212
+ for(var i = 0; i < 2; i++) {
213
+ element += '<section id="'+ section_id +'" class="fc-item fc-item--two fc-item--border">';
214
+ element += '<input class="fc-search" type="text" name="search" placeholder="Buscar notícia">';
215
+ element += '<a href="#" class="fc-link fc-link--absolute"></a>';
216
+ element += '<h2 class="fc-caption"></h2>';
217
+ element += '<figure class="fc-figure fc-figure--block fc-figure--large">';
218
+ element += '<img class="fc-image" src="<%= image_url('cb-image-default.jpg') %>">';
219
+ element += '<input class="fc-tools__input fc-tools__input--upload" type="file" name="image" id="'+ section_id +'">';
220
+ element += '<div class="fc-tools fc-tools--center">';
221
+ element += '<a class="fc-tools__btn fc-tools__btn--upload fa fa-camera" href="#'+ section_id + '"></a>';
222
+ element += '</div>';
223
+ element += '</figure>';
224
+ element += '<h1 class="fc-title fc-title--small"></h1>';
225
+ element += '<p class="fc-text"></p>';
226
+ element += '</section>';
227
+
228
+ sections.push(section_id);
229
+ section_id = generateID();
230
+ }
231
+
232
+ element += '</div>';
233
+ element += '</div>';
234
+
235
+ container.append(element);
236
+
237
+ for(var i = 0; i < sections.length; i++) {
238
+ autocomplete(sections[i]);
239
+ addEventToInputFile(sections[i]);
240
+ }
241
+
242
+ scrollTo(row_id);
243
+ break;
244
+ }
245
+
246
+ editable();
247
+ });
248
+
249
+ // slide active
250
+ var slideActive = function(container) {
251
+ if(container) {
252
+ container.owlCarousel({
253
+ singleItem: true,
254
+ slideSpeed: 500,
255
+ autoPlay: false,
256
+ stopOnHover: true,
257
+ paginationSpeed: 500,
258
+ rewindSpeed: 1000,
259
+ navigation: true,
260
+ touchDrag: false,
261
+ mouseDrag: false,
262
+ navigationText: ['&lsaquo;','&rsaquo;']
263
+ });
264
+ }
265
+ };
266
+
267
+ // slide destroy
268
+ var slideDestroy = function(container) {
269
+ if(container.length) {
270
+ container.data('owlCarousel').destroy();
271
+ }
272
+ }
273
+
274
+ // slide add
275
+ var slideAdd = function(row_id, reference) {
276
+ section_id = generateID();
277
+
278
+ var element = '<div class="fc-item fc-slide__owl" id="'+ section_id +'">';
279
+ element += '<input class="fc-search" type="text" name="search" placeholder="Buscar notícia">';
280
+ element += '<div class="fc-slide__item">';
281
+ element += '<div class="fc-tools fc-tools--center">';
282
+ element += '<a class="fc-tools__btn fc-tools__btn--upload fa fa-camera" href="#'+ section_id + '"></a>';
283
+ element += '<a class="fc-tools__btn fc-tools__btn--slide-add fa fa-plus" data-row="'+ row_id +'" href="#'+ section_id +'"></a>';
284
+ element += '<a class="fc-tools__btn fc-tools__btn--slide-remove fa fa-trash" data-row="'+ row_id +'" href="#'+ section_id +'"></a>';
285
+ element += '</div>';
286
+ element += '<a href="#" class="fc-link fc-slide__link"></a>';
287
+ element += '<h2 class="fc-caption fc-slide__caption"></h2>';
288
+ element += '<figure class="fc-slide__figure">';
289
+ element += '<img class="fc-slide__image" src="<%= image_url('cb-image-default.jpg') %>">';
290
+ element += '<input class="fc-tools__input fc-tools__input--upload" type="file" name="image" id="'+ section_id +'">';
291
+ element += '</figure>';
292
+ element += '<div class="fc-slide__content">';
293
+ element += '<h1 class="fc-title fc-slide__title"></h1>';
294
+ element += '<p class="fc-text fc-slide__text"></p>';
295
+ element += '</div>';
296
+ element += '</section>';
297
+ element += '</div>';
298
+ element += '</div>';
299
+
300
+ var container = $('#'+ row_id +' .fc-slide');
301
+
302
+ container.data('owlCarousel').addItem(element, [0]);
303
+ container.data('owlCarousel').jumpTo(0);
304
+
305
+ autocomplete(section_id);
306
+ addEventToInputFile(section_id);
307
+ editable();
308
+ }
309
+
310
+ // slide remove
311
+ var slideRemove = function(row_id, reference) {
312
+ var container = $('#'+ row_id +' .fc-slide');
313
+ var items = $('#'+ row_id +' .fc-slide__owl');
314
+
315
+ for(i = 0; i < items.length; i++) {
316
+ if('#' + items[i].id == reference.attr('href')) {
317
+ container.data('owlCarousel').removeItem(i);
318
+ container.data('owlCarousel').jumpTo(i);
319
+
320
+ break;
321
+ }
322
+ }
323
+ }
324
+
325
+ // add event on input file
326
+ var addEventToInputFile = function(id) {
327
+ $('#' + id + ' input:file').on('change', fileSelectAndUpload);
328
+ };
329
+
330
+ // upload file via ajax
331
+ var fileSelectAndUpload = function(evt) {
332
+ var file = evt.target.files[0];
333
+
334
+ if(file) {
335
+ var formData = new FormData();
336
+ formData.append('featured_content_image', file);
337
+
338
+ $.ajax({
339
+ url: 'create_images',
340
+ data: formData,
341
+ cache: false,
342
+ contentType: false,
343
+ processData: false,
344
+ type: 'PUT',
345
+ beforeSend: function() {
346
+ $('#' + evt.target.id).find('figure').append('<div class="fc-loading"></div>');
347
+ $('.fc-tools--center').addClass('fc-tools--disabled');
348
+ },
349
+ complete: function(){
350
+ $('.fc-loading').remove();
351
+ $('.fc-tools--center').removeClass('fc-tools--disabled');
352
+ }
353
+ }).done(function(e) {
354
+ $('#' + evt.target.id).find('img').attr('src', e.image.thumb.url);
355
+ }).fail(function(e) {
356
+ alert('error: ' + e);
357
+ });
358
+ }
359
+ };
360
+
361
+ // scroll to
362
+ var scrollTo = function(id) {
363
+ if(id) {
364
+ $('html, body').animate({
365
+ scrollTop: $('#' + id).offset().top
366
+ }, 400);
367
+ }
368
+ };
369
+
370
+ // generate random id
371
+ var generateID = function() {
372
+ return '_' + Math.random().toString(36).substr(2, 9);
373
+ };
374
+
375
+ // content editable
376
+ var editable = function() {
377
+ $('.fc-title').attr('contenteditable', 'true');
378
+ $('.fc-text').attr('contenteditable', 'true');
379
+ $('.fc-caption').attr('contenteditable', 'true');
380
+ }
381
+
382
+ autocomplete = function(id) {
383
+ $('#' + id + ' input:text').autocomplete({
384
+ source: "search_content",
385
+ minLength: 5,
386
+ select: function(event, ui) {
387
+ console.log(ui.item);
388
+ $("#" + id + ' .fc-title').text(ui.item.title);
389
+ $("#" + id + ' .fc-text').text(ui.item.summary);
390
+ $("#" + id + ' .fc-caption').text(ui.item.content_builder_category.name);
391
+ $("#" + id + ' .fc-link').attr('href', '/noticias/'+ ui.item.content_builder_category.slug +'/' + ui.item.slug);
392
+ return false;
393
+ }
394
+ }).autocomplete("instance")._renderItem = function(ul, item) {
395
+ return $( "<li>" )
396
+ .append( "<a>" + item.title + "</a>" )
397
+ .appendTo( ul );
398
+ };
399
+ };