├── .document ├── .gitignore ├── .ruby-version ├── Gemfile ├── LICENSE.txt ├── README.rdoc ├── Rakefile ├── app ├── assets │ ├── images │ │ └── inline_forms │ │ │ └── glass_plate.gif │ ├── javascripts │ │ └── inline_forms │ │ │ └── inline_forms.js │ └── stylesheets │ │ └── inline_forms │ │ ├── devise.scss │ │ ├── foundation_and_overrides.scss │ │ └── inline_forms.scss ├── controllers │ ├── concerns │ │ ├── cancan_concern.rb │ │ └── versions_concern.rb │ ├── geo_code_curacao_controller.rb │ ├── inline_forms_application_controller.rb │ └── inline_forms_controller.rb ├── helpers │ ├── form_elements │ │ ├── absence_list.rb │ │ ├── audio_field.rb │ │ ├── check_box.rb │ │ ├── check_list.rb │ │ ├── chicas_dropdown_with_family_members.rb │ │ ├── chicas_family_photo_list.rb │ │ ├── chicas_photo_list.rb │ │ ├── ckeditor.rb │ │ ├── date.rb │ │ ├── decimal_field.rb │ │ ├── devise_password_field.rb │ │ ├── dns_records.rb │ │ ├── dropdown.rb │ │ ├── dropdown_with_integers.rb │ │ ├── dropdown_with_other.rb │ │ ├── dropdown_with_values.rb │ │ ├── dropdown_with_values_with_stars.rb │ │ ├── file_field.rb │ │ ├── geo_code_curacao.rb │ │ ├── header.rb │ │ ├── image_field.rb │ │ ├── info.rb │ │ ├── info_list.rb │ │ ├── integer_field.rb │ │ ├── kansen_slider.rb │ │ ├── money_field.rb │ │ ├── month_select.rb │ │ ├── month_year_picker.rb │ │ ├── move.rb │ │ ├── multi_image_field.rb │ │ ├── pdf_link.rb │ │ ├── plain_text_area.rb │ │ ├── question_list.rb │ │ ├── radio_button.rb │ │ ├── scale_with_integers.rb │ │ ├── scale_with_values.rb │ │ ├── simple_file_field.rb │ │ ├── slider_with_values.rb │ │ ├── text_area.rb │ │ ├── text_area_without_ckeditor.rb │ │ ├── text_field.rb │ │ └── time.rb │ └── inline_forms_helper.rb ├── models │ ├── concerns │ │ └── inline_forms │ │ │ └── soft_deletable.rb │ └── geo_code_curacao.rb ├── validators │ ├── curacao_id_number_validator.rb │ ├── is_curacao_phone_validator.rb │ ├── is_email_address_validator.rb │ └── must_be_a_value_validator.rb └── views │ ├── devise │ ├── inline_forms │ │ ├── _content_for_devise_login.html.erb │ │ ├── _content_for_passwords_edit.html.erb │ │ └── _content_for_passwords_new.html.erb │ ├── passwords │ │ ├── _top-bar-and-flash.html.erb │ │ ├── edit.html.erb │ │ └── new.html.erb │ ├── sessions │ │ ├── _flash.html.erb │ │ ├── _form.html.erb │ │ ├── _top-bar-and-flash.html.erb │ │ ├── _top-bar.html.erb │ │ └── new.html.erb │ └── shared │ │ ├── _header_and_errors.html.erb │ │ └── _links.erb │ ├── geo_code_curacao │ ├── list_streets.html.erb │ └── list_streets.js.erb │ ├── inline_forms │ ├── _close.html.erb │ ├── _edit.html.erb │ ├── _flash.html.erb │ ├── _header.html.erb │ ├── _list.html.erb │ ├── _new.html.erb │ ├── _new_nested.html.erb │ ├── _show.html.erb │ ├── _tree.html.erb │ ├── _versions.html.erb │ ├── _versions_list.html.erb │ ├── close.js.erb │ ├── edit.js.erb │ ├── extract_translations.erb │ ├── list.js.erb │ ├── new.js.erb │ ├── record_destroyed.js.erb │ ├── show.js.erb │ ├── show_element.js.erb │ ├── show_undo.js.erb │ ├── update.js.erb │ ├── versions.js.erb │ └── versions_list.js.erb │ └── layouts │ ├── application.html.erb │ ├── devise.html.erb │ └── inline_forms.html.erb ├── bin ├── inline_forms ├── inline_forms_app_template.rb └── inline_forms_installer_core.rb ├── inline_forms.gemspec └── lib ├── generators ├── USAGE ├── assets │ ├── javascripts │ │ └── ckeditor │ │ │ └── config.js │ └── stylesheets │ │ ├── inline_forms.scss │ │ └── inline_forms_devise.css ├── inline_forms_generator.rb └── templates │ ├── _inline_forms_tabs.html.erb │ ├── application_record.rb │ ├── capistrano │ ├── Capfile │ ├── deploy.rb │ └── production.rb │ ├── controller.erb │ ├── migration.erb │ ├── model.erb │ ├── test.erb │ └── unicorn │ └── production.rb ├── inline_forms.rb ├── inline_forms └── version.rb ├── locales ├── inline_forms.en.yml └── inline_forms.nl.yml ├── otherstuff ├── 20120310065554_inline_forms_create_view_for_translations.rb ├── add_roles.sql ├── mkiftrans ├── mkrole └── roles_users.sql └── vagrant └── vagrantbox-inline_forms.zip /.document: -------------------------------------------------------------------------------- 1 | lib/**/*.rb 2 | bin/* 3 | - 4 | features/**/*.feature 5 | LICENSE.txt 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # rcov generated 2 | coverage 3 | 4 | # rdoc generated 5 | rdoc 6 | 7 | # yard generated 8 | doc 9 | .yardoc 10 | 11 | # bundler 12 | .bundle 13 | 14 | # jeweler generated 15 | pkg 16 | 17 | # other (Lemuel I think) 18 | .project 19 | .vscode 20 | 21 | # Builds 22 | *.gem 23 | 24 | Gemfile.lock 25 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.2.1 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 - 2021 Ace Suares 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | = inline_forms 2 | 3 | Inline Forms is almost a complete admin application. You can try it out easily. 4 | 5 | = Usage 6 | 7 | gem install inline_forms 8 | 9 | If you want to just start a new app called MyApp: 10 | 11 | inline_forms create MyApp 12 | 13 | If you want to use mysql instead of sqlite as development database: 14 | 15 | inline_forms create MyApp --database mysql 16 | 17 | If you want to install the example application: 18 | 19 | inline_forms create MyApp -d sqlite --example 20 | 21 | Then point your browser to http://localhost:3000/apartments and log in with admin@example.com / admin999 22 | 23 | You can install the example application manually if you like: 24 | 25 | inline_forms create MyApp 26 | cd MyApp 27 | rails g inline_forms Picture name:string caption:string image:image_field description:text apartment:belongs_to _presentation:'#{name}' 28 | rails generate uploader Image 29 | rails g inline_forms Apartment name:string title:string description:text pictures:has_many pictures:associated _enabled:yes _presentation:'#{name}' 30 | bundle exec rake db:migrate 31 | rails s 32 | 33 | Then point your browser to http://localhost:3000/apartments and log in with admin@example.com / admin999 34 | 35 | = Build a vagrant virtualbox box for easier development 36 | 37 | Go ahead and unzip lib/vagrant/vagrantbox-inline_forms.zip. Enter the created directory with 38 | 39 | cd vagrantbox-inline_forms 40 | 41 | then issue 42 | 43 | vagrant up 44 | 45 | after a while you should be able to use the created box like this: 46 | 47 | vagrant ssh 48 | 49 | Once inside the box, goto /vagrant and install_stuff: 50 | 51 | cd /vagrant 52 | ./install_stuff 53 | 54 | This should update your box, install rvm and ruby and inline_forms, and create an example app. 55 | 56 | 57 | == Disclaimer 58 | 59 | It's work in progress. Until I learn to use git branch, new releases break as easy as Elijah Price's bones. 60 | 61 | 62 | == Copyright 63 | 64 | Copyright (c) 2011-2015 Ace Suares. See LICENSE.txt for further details. 65 | 66 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler' 2 | Bundler::GemHelper.install_tasks 3 | -------------------------------------------------------------------------------- /app/assets/images/inline_forms/glass_plate.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acesuares/inline_forms/9d25349c247f9473a09ccdb2655d17532598b6a5/app/assets/images/inline_forms/glass_plate.gif -------------------------------------------------------------------------------- /app/assets/javascripts/inline_forms/inline_forms.js: -------------------------------------------------------------------------------- 1 | //= require jquery 2 | //= require jquery_ujs 3 | //= require jquery.ui.all 4 | //= require jquery.timepicker.js 5 | //= require foundation 6 | //= require jquery.remotipart 7 | //= require autocomplete-rails 8 | 9 | $(function(){ $(document).foundation(); }); 10 | // initialize datepickers 11 | $(document).ready(function() { 12 | $.datepicker.setDefaults({ 13 | changeMonth : true, 14 | changeYear : true, 15 | yearRange: '-100:+100', 16 | dateFormat: 'dd-mm-yy' 17 | }); 18 | }); 19 | 20 | // get rid of translation_missing tooltips 21 | $(document).ready(function() { 22 | $(this).on('mouseover', '.translation_missing', function() { 23 | $(this).attr('title', ''); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /app/assets/stylesheets/inline_forms/devise.scss: -------------------------------------------------------------------------------- 1 | @import url(http://fonts.googleapis.com/css?family=Open+Sans:400,400italic); 2 | @import 'foundation_and_overrides'; 3 | 4 | .contain-to-grid { 5 | background-color: $body-bg !important; 6 | } 7 | 8 | #inline_forms_devise_outer_container a { 9 | color: #A3381E; 10 | } 11 | 12 | #inline_forms_devise_top_nav_bar { 13 | background-color: #A3381E; 14 | a { 15 | color: #FFFFFF; 16 | } 17 | } 18 | 19 | #inline_forms_devise_flash_div { 20 | border-top: 0.5em solid #fade7a; 21 | .flash { 22 | margin-top: 0.2em; 23 | padding: 0.5em; 24 | color: #A3381E; 25 | font-size: 130%; 26 | font-weight: bold; 27 | line-height: 120%; 28 | background-color: white; 29 | border: none; 30 | } 31 | } 32 | 33 | #inline_forms_devise_header_row{ 34 | h1 { 35 | text-align: center; 36 | margin: 30px 0; 37 | color: #A3381E; 38 | } 39 | } 40 | 41 | #inline_forms_devise_container { 42 | .row { 43 | margin-bottom: 30px; 44 | } 45 | } 46 | 47 | #inline_forms_devise_form_column { 48 | } 49 | 50 | #inline_forms_devise_form { 51 | label { 52 | padding-bottom: 0.2em; 53 | padding-left: 0.3em; 54 | } 55 | input[type=checkbox] { 56 | position: relative; 57 | top: 2px; 58 | } 59 | .lower { 60 | top: 15px; 61 | } 62 | #error_explanation { 63 | color: #A3381E; 64 | h2 { 65 | color: #A3381E; 66 | font-size: 120%; 67 | font-weight: bolder; 68 | } 69 | } 70 | } 71 | 72 | #inline_forms_devise_content_column { 73 | hr { 74 | width: 96%; 75 | margin: auto; 76 | } 77 | } 78 | 79 | #inline_forms_devise_content { 80 | padding: 0 1em 1em 3em; 81 | h1 { 82 | text-align: center; 83 | margin: 0 0 0.5em 0; 84 | color: #A3381E; 85 | font-weight: bolder; 86 | } 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /app/assets/stylesheets/inline_forms/foundation_and_overrides.scss: -------------------------------------------------------------------------------- 1 | @import 'foundation/functions'; 2 | 3 | $include-html-classes: true; 4 | $include-html-global-classes: $include-html-classes; 5 | $font-family-sans-serif: "Open Sans", sans-serif; 6 | 7 | @import 'foundation'; 8 | -------------------------------------------------------------------------------- /app/assets/stylesheets/inline_forms/inline_forms.scss: -------------------------------------------------------------------------------- 1 | // inline_forms 2 | @import url(http://fonts.googleapis.com/css?family=Open+Sans:400,400italic); 3 | @import 'foundation-icons'; 4 | @import 'themes/jquery.ui.sunny'; 5 | @import 'jquery.ui.all'; 6 | @import 'foundation_and_overrides'; 7 | 8 | .contain-to-grid { 9 | background-color: $body-bg !important; 10 | } 11 | 12 | input { 13 | margin: 2px 0 !important; 14 | } 15 | 16 | select { 17 | background-color: #fff8e0 !important; 18 | border: 0 !important; 19 | margin: 2px 0 !important; 20 | padding: 0; 21 | 22 | } 23 | select:hover, select:focus { 24 | background-color: lighten(#fff8e0, 2%) !important; 25 | border: 0 !important; 26 | } 27 | 28 | #inline_forms_application_top_bar { 29 | background-color: #A3381E; 30 | color: #FFFFFF; 31 | .top-bar-section li a { 32 | background-color: #A3381E; 33 | } 34 | } 35 | 36 | #inline_forms_model_top_bar { 37 | background-color: #E1C150; 38 | padding-top: 45px; 39 | height: 90px; 40 | .top-bar-section { 41 | .right, li, .has-form { 42 | background-color: #E1C150; 43 | } 44 | .inline_forms_model_top_bar_buttons { 45 | top: 4px !important; 46 | padding: 7px 0 7px 0 !important; 47 | margin: 0 !important; 48 | } 49 | .new_button { 50 | background-color: #E1C150; 51 | color: #B94C32; 52 | font-size: 1.3rem; 53 | padding: 0 2rem 0 1rem; 54 | } 55 | .new_button:hover, .new_button:focus { 56 | color: white; 57 | -webkit-transition-property: color; 58 | transition-property: color; 59 | } 60 | input[type=text]:hover, input[type=text]:focus { 61 | background-color: lighten(#fff8e0, 5%); 62 | -webkit-transition-property: background-color; 63 | transition-property: background-color; 64 | } 65 | } 66 | } 67 | 68 | #inline_forms_model_top_bar_container { 69 | z-index: 9; 70 | } 71 | 72 | #outer_container { 73 | width: 100%; 74 | position: absolute; 75 | top: 90px; 76 | } 77 | 78 | .top-level a { 79 | font-weight: bold; 80 | font-size: 110%; 81 | } 82 | .list_container { 83 | .row { 84 | font-size: 1.2rem; 85 | font-weight: normal; 86 | line-height: 2.2rem; 87 | margin: 0 auto !important; 88 | } 89 | .odd { 90 | background-color: #FBE38E; 91 | } 92 | .even { 93 | background-color: #FBEEC1; 94 | } 95 | } 96 | 97 | .inline_forms_list, .new_record { 98 | .row.odd, .row.even { 99 | font-size: 1rem !important; 100 | font-weight: normal !important; 101 | } 102 | .row.form_element_header { 103 | border-top: 1px solid #B94C32; 104 | background-color: rgb(239, 202, 75); 105 | font-weight: normal !important; 106 | font-size: 1.3rem !important; 107 | } 108 | } 109 | 110 | .new_record { 111 | .button { 112 | margin: 0; 113 | padding: 0.5rem; 114 | } 115 | } 116 | 117 | .object_presentation { 118 | background-color: #B94C32; 119 | color: white; 120 | .close_button { 121 | background-color: #B94C32; 122 | font-size: 1.3rem; 123 | padding: 0 1rem 0 1rem; 124 | margin: 0; 125 | } 126 | .close_button:hover, .close_button:focus { 127 | background-color: #B94C32; 128 | color: #FBEEC1; 129 | -webkit-transition-property: color; 130 | transition-property: color; 131 | } 132 | } 133 | 134 | .list_container { 135 | .row.odd, .row.even { 136 | font-size: 1rem !important; 137 | font-weight: normal !important; 138 | } 139 | .row.form_element_header { 140 | border-top: 1px solid #B94C32; 141 | background-color: rgb(239, 202, 75); 142 | font-weight: normal !important; 143 | font-size: 1.3rem !important; 144 | } 145 | } 146 | 147 | 148 | 149 | .associated_auto_header { 150 | border-top: 1px solid #B94C32; 151 | .new_button { 152 | background-color: rgb(239, 202, 75); 153 | font-size: 1.5rem; 154 | color: #B94C32; 155 | padding: 0 0.5rem 0 1rem; 156 | margin: 0; 157 | } 158 | .new_button:hover, .new_button:focus { 159 | background-color: rgb(239, 202, 75); 160 | color: white; 161 | -webkit-transition-property: color; 162 | transition-property: color; 163 | } 164 | .close_button { 165 | background-color: rgb(239, 202, 75); 166 | font-size: 1.5rem; 167 | color: #B94C32; 168 | padding: 0 0.5rem 0 1rem; 169 | margin: 0; 170 | } 171 | .close_button:hover, .new_button:focus { 172 | background-color: rgb(239, 202, 75); 173 | color: white; 174 | -webkit-transition-property: color; 175 | transition-property: color; 176 | } 177 | } 178 | 179 | .pagination { 180 | font-weight: normal; 181 | font-size: 0.9em; 182 | a:hover { 183 | color: #B94C32; 184 | -webkit-transition-property: color; 185 | -webkit-transition-duration: 0.3s; 186 | transition-property: color; 187 | transition-duration: 0.3s; 188 | } 189 | em { 190 | color: #B94C32; 191 | font-weight: bold; 192 | font-style: normal; 193 | } 194 | span.disabled { 195 | color: #AAA; 196 | } 197 | } 198 | 199 | .record_footer { 200 | background-color: rgb(239, 202, 75); 201 | height: 0.2em; 202 | border-bottom: 1px solid #B94C32; 203 | margin-bottom: 1.5em; 204 | } 205 | 206 | .custom-combobox { 207 | position: relative; 208 | display: inline-block; 209 | } 210 | .custom-combobox-toggle { 211 | position: absolute; 212 | top: 0; 213 | bottom: 0; 214 | margin-left: -1px; 215 | padding: 0; 216 | /* support: IE7 */ 217 | *height: 1.7em; 218 | *top: 0.1em; 219 | } 220 | .custom-combobox-input { 221 | margin: 0; 222 | padding: 0.3em; 223 | } 224 | 225 | 226 | .column { 227 | padding-right: 0 !important; 228 | } 229 | 230 | .top-bar input, .top-bar .button { 231 | top: 4px !important; 232 | } 233 | 234 | .top-bar-section { 235 | padding-left: rem-calc(12) !important; 236 | padding-right: rem-calc(12) !important; 237 | } 238 | 239 | .first-bar { 240 | margin-bottom: 0 !important; 241 | } 242 | .second-bar { 243 | margin-top: 1px !important; 244 | margin-bottom: 0 !important; 245 | } 246 | 247 | #switch_user_identifier { 248 | font-size: smaller; 249 | select { 250 | width: 5em; 251 | } 252 | } 253 | 254 | .flash { 255 | padding: 0.3em; 256 | color: #A3381E; 257 | font-size: 130%; 258 | font-weight: bold; 259 | line-height: 120%; 260 | background-color: white; 261 | border-top: 0.3em solid #fade7a; 262 | } 263 | 264 | .error { 265 | color: #ffffff; 266 | font-weight: bold; 267 | background-color: #a70f0f; 268 | padding: 0.3em; 269 | margin-bottom: 0.5em; 270 | } 271 | .success { 272 | color: #ffffff; 273 | font-weight: bold; 274 | border-bottom: 1px solid #cccccc; 275 | background-color: #4f8d0d; 276 | padding: 0.3em; 277 | margin-bottom: 0.5em; 278 | } 279 | 280 | .ckeditor_area { 281 | position: relative; 282 | } 283 | 284 | .ckeditor_area .glass_plate { 285 | position: absolute; 286 | top: -1px; 287 | width: 98%; 288 | height: 232px; 289 | border: 0; 290 | } 291 | 292 | .ckeditor_area .cke_top, .ckeditor_area .cke_bottom, .ckeditor_area .cke_border { 293 | display: none; 294 | } 295 | 296 | /* jQuery ui Slider 8 */ 297 | .slider { 298 | width: 300px; 299 | float: left; 300 | } 301 | .slider_value { 302 | float: left; 303 | min-width: 60px; 304 | text-align: right; 305 | font-family: monospace; 306 | } 307 | 308 | 309 | /* LEFT */ 310 | 311 | #category_id { 312 | margin-top: -2px !important; 313 | } 314 | 315 | #input_search { 316 | border: none !important; 317 | margin-top: -2px; 318 | } 319 | 320 | #inline_forms_model_top_bar .top-bar-section .inline_forms_model_top_bar_buttons { 321 | top: 6px !important; 322 | } 323 | -------------------------------------------------------------------------------- /app/controllers/concerns/cancan_concern.rb: -------------------------------------------------------------------------------- 1 | module CancanConcern 2 | extend ActiveSupport::Concern 3 | 4 | included do 5 | helper_method :cancan_disabled?, :cancan_enabled? 6 | end 7 | 8 | class_methods do 9 | def cancan_enabled? 10 | begin 11 | CanCan::Ability && true 12 | rescue NameError 13 | false 14 | end 15 | end 16 | end 17 | 18 | def cancan_enabled? 19 | self.class.cancan_enabled? 20 | end 21 | 22 | def cancan_disabled? 23 | ! self.class.cancan_enabled? 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /app/controllers/concerns/versions_concern.rb: -------------------------------------------------------------------------------- 1 | module VersionsConcern 2 | extend ActiveSupport::Concern 3 | 4 | included do 5 | before_action :set_paper_trail_whodunnit 6 | end 7 | 8 | def list_versions 9 | @update_span = params[:update] 10 | @object = referenced_object 11 | close = params[:close] || false 12 | if close 13 | respond_to do |format| 14 | format.js { render :versions } 15 | end 16 | else 17 | respond_to do |format| 18 | format.html { } unless @Klass.not_accessible_through_html? 19 | format.js { render :versions_list } 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /app/controllers/geo_code_curacao_controller.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | # Used in autocomplete 3 | # 4 | class GeoCodeCuracaoController < ApplicationController 5 | def list_streets 6 | @term = params[:term] 7 | @streets = GeoCodeCuracao.lookup('%' + @term + '%') 8 | end 9 | 10 | end 11 | -------------------------------------------------------------------------------- /app/controllers/inline_forms_application_controller.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | class InlineFormsApplicationController < ActionController::Base 3 | protect_from_forgery 4 | layout 'devise' if :devise_controller? 5 | 6 | # limit available locales by setting this. Override in applicaton_controller. 7 | I18n.available_locales = [ :en, :nl, :pp ] 8 | 9 | #set the locale based on the subdomain 10 | def set_locale 11 | I18n.locale = extract_locale_from_subdomain || I18n.default_locale 12 | end 13 | 14 | # Get locale code from request subdomain (like http://it.application.local:3000) 15 | def extract_locale_from_subdomain 16 | locale = request.subdomains.first 17 | return nil if locale.nil? 18 | I18n.available_locales.include?(locale.to_sym) ? locale.to_s : nil 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /app/controllers/inline_forms_controller.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | # == Generic controller for the inline_forms plugin. 3 | # === Usage 4 | # If you have an Example class, make an ExampleController 5 | # that is a subclass of InlineFormsController 6 | # class ExampleController < InlineFormsController 7 | # end 8 | # That's it! It'll work. But please read about the InlineForms::InlineFormsGenerator first! 9 | # 10 | # You can override the methods in your ExampleController 11 | # def index 12 | # @objects=@Klass.all 13 | # end 14 | # 15 | # 16 | # @objects holds the objects (in this case Examples) 17 | # and @Klass will be set to Example by the getKlass before filter. 18 | # 19 | # === How it works 20 | # The getKlass before_action extracts the class and puts it in @Klass 21 | # 22 | # @Klass is used in the InlineFormsHelper 23 | # 24 | class InlineFormsController < ApplicationController 25 | include CancanConcern 26 | include VersionsConcern 27 | 28 | before_action :getKlass 29 | 30 | load_and_authorize_resource :except => :revert, :no_params => true if cancan_enabled? 31 | # :index shows a list of all objects from class @Klass, using will_paginate, 32 | # including a link to 'new', that allows you to create a new record. 33 | def index 34 | @update_span = params[:update] 35 | @parent_class = params[:parent_class] 36 | @parent_id = params[:parent_id] 37 | @ul_needed = params[:ul_needed] 38 | # if the parent_class is not nill, we are in associated list and we don't search there. 39 | # also, make sure the Model that you want to do a search on has a :name attribute. TODO 40 | conditions = nil 41 | if @parent_class.nil? || @Klass.reflect_on_association(@parent_class.underscore.to_sym).nil? 42 | conditions = [ @Klass.table_name + "." + @Klass.order_by_clause + " like ?", "%#{params[:search]}%" ] if @Klass.respond_to?(:order_by_clause) && ! @Klass.order_by_clause.nil? 43 | else 44 | foreign_key = @Klass.reflect_on_association(@parent_class.underscore.to_sym).options[:foreign_key] || @parent_class.foreign_key 45 | conditions = [ "#{foreign_key} = ?", @parent_id ] 46 | end 47 | # if we are using cancan, then make sure to select only accessible records 48 | @objects ||= @Klass.accessible_by(current_ability) if cancan_enabled? 49 | @objects ||= @Klass 50 | @objects = @objects.order(@Klass.table_name + "." + @Klass.order_by_clause) if @Klass.respond_to?(:order_by_clause) && ! @Klass.order_by_clause.nil? 51 | @objects = @objects.where(conditions).paginate(:page => params[:page]) 52 | respond_to do |format| 53 | format.html { render 'inline_forms/_list', :layout => 'inline_forms' } unless @Klass.not_accessible_through_html? 54 | format.js { render :list } 55 | end 56 | end 57 | 58 | # :new prepares a new object, updates the list of objects and replaces it with 59 | # an empty form. After pressing OK or Cancel, the list of objects is retrieved 60 | # in the same way as :index 61 | def new 62 | @object ||= @Klass.new 63 | @update_span = params[:update] 64 | @parent_class = params[:parent_class] 65 | begin 66 | @parent_id = params[:parent_id] 67 | foreign_key = @Klass.reflect_on_association(@parent_class.underscore.to_sym).options[:foreign_key] || @parent_class.foreign_key 68 | @object[foreign_key] = @parent_id 69 | end unless @parent_class.nil? || @Klass.reflect_on_association(@parent_class.underscore.to_sym).nil? 70 | 71 | @object.inline_forms_attribute_list = @inline_forms_attribute_list if @inline_forms_attribute_list 72 | respond_to do |format| 73 | format.html { render 'inline_forms/_new', :layout => 'inline_forms' } unless @Klass.not_accessible_through_html? 74 | format.js { } 75 | end 76 | end 77 | 78 | # :edit presents a form to edit one specific attribute from an object 79 | def edit 80 | @object = referenced_object 81 | @attribute = params[:attribute] 82 | @form_element = params[:form_element] 83 | @sub_id = params[:sub_id] 84 | @update_span = params[:update] 85 | respond_to do |format| 86 | format.html { } unless @Klass.not_accessible_through_html? 87 | format.js { } 88 | end 89 | end 90 | 91 | # :create creates the object made with :new. 92 | # It then presents the list of objects. 93 | def create 94 | @object ||= @Klass.new 95 | @update_span = params[:update] 96 | attributes = @inline_forms_attribute_list || @object.inline_forms_attribute_list 97 | attributes.each do | attribute, name, form_element | 98 | send("#{form_element.to_s}_update", @object, attribute) unless form_element == :tree || form_element == :associated || (cancan_enabled? && cannot?(:read, @object, attribute)) 99 | end 100 | @parent_class = params[:parent_class] 101 | @parent_id = params[:parent_id] 102 | # for the logic behind the :conditions see the #index method. 103 | conditions = nil 104 | if @parent_class.nil? || @Klass.reflect_on_association(@parent_class.underscore.to_sym).nil? 105 | conditions = [ @Klass.table_name + "." + @Klass.order_by_clause + " like ?", "%#{params[:search]}%" ] if @Klass.respond_to?(:order_by_clause) && ! @Klass.order_by_clause.nil? 106 | else 107 | foreign_key = @Klass.reflect_on_association(@parent_class.underscore.to_sym).options[:foreign_key] || @parent_class.foreign_key 108 | conditions = [ "#{foreign_key} = ?", @parent_id ] 109 | @object[foreign_key] = @parent_id 110 | end 111 | 112 | if @object.save 113 | flash.now[:success] = t('success', :message => @object.class.model_name.human) 114 | @objects = @Klass 115 | @objects = @Klass.accessible_by(current_ability) if cancan_enabled? 116 | @objects = @objects.order(@Klass.table_name + "." + @Klass.order_by_clause) if @Klass.respond_to?(:order_by_clause) && ! @Klass.order_by_clause.nil? 117 | @objects = @objects.where(conditions).paginate(:page => params[:page]) 118 | @object = nil 119 | respond_to do |format| 120 | format.js { render :list} 121 | end 122 | else 123 | flash.now[:header] = ["Kan #{@object.class.to_s.underscore} niet aanmaken."] 124 | flash.now[:error] = @object.errors.to_a 125 | respond_to do |format| 126 | @object.inline_forms_attribute_list = attributes 127 | format.js { render :new} 128 | end 129 | end 130 | end 131 | 132 | # :update updates a specific attribute from an object. 133 | def update 134 | @object = referenced_object 135 | @attribute = params[:attribute] 136 | @form_element = params[:form_element] 137 | @sub_id = params[:sub_id] 138 | @update_span = params[:update] 139 | send("#{@form_element.to_s}_update", @object, @attribute) 140 | @object.save 141 | respond_to do |format| 142 | format.html { } unless @Klass.not_accessible_through_html? 143 | format.js { } 144 | end 145 | end 146 | 147 | # :show shows one attribute (attribute) from a record (object). 148 | # It includes the link to 'edit' 149 | def show 150 | @object = referenced_object 151 | @attribute = params[:attribute] 152 | @form_element = params[:form_element] 153 | close = params[:close] || false 154 | if @form_element == "associated" 155 | @sub_id = params[:sub_id] 156 | if @sub_id.to_i > 0 157 | @associated_record_id = @object.send(@attribute.to_s.singularize + "_ids").index(@sub_id.to_i) 158 | @associated_record = @object.send(@attribute)[@associated_record_id] 159 | end 160 | end 161 | if @form_element == "has_one" 162 | @associated_record = @object.send(@attribute) 163 | @associated_record_id = @associated_record.id 164 | end 165 | @update_span = params[:update] 166 | if @attribute.nil? 167 | respond_to do |format| 168 | @attributes = @object.inline_forms_attribute_list 169 | if close 170 | format.js { render :close } 171 | else 172 | format.js { } 173 | end 174 | end 175 | else 176 | respond_to do |format| 177 | format.html { } unless @Klass.not_accessible_through_html? 178 | format.js { render :show_element } 179 | end 180 | end 181 | end 182 | 183 | # :soft_delete 184 | def soft_delete 185 | @update_span = params[:update] 186 | @object = referenced_object 187 | # destroy the object 188 | @object.soft_delete(current_user) 189 | respond_to do |format| 190 | format.html { } unless @Klass.not_accessible_through_html? 191 | format.js { render :close } 192 | end 193 | end 194 | 195 | # :soft_restore 196 | def soft_restore 197 | @update_span = params[:update] 198 | @object = referenced_object 199 | # restore the object 200 | @object.soft_restore 201 | respond_to do |format| 202 | format.html { } unless @Klass.not_accessible_through_html? 203 | format.js { render :close } 204 | end 205 | end 206 | 207 | # :destroy destroys the record. There is no undo! 208 | def destroy 209 | @update_span = params[:update] 210 | @object = referenced_object 211 | if current_user.role? :superadmin 212 | # destroy the object 213 | @undo_object = @object.versions.last 214 | @object.destroy 215 | respond_to do |format| 216 | format.html { } unless @Klass.not_accessible_through_html? 217 | format.js { render :record_destroyed } 218 | end 219 | end 220 | end 221 | 222 | # :revert works like undo. 223 | # Thanks Ryan Bates: http://railscasts.com/episodes/255-undo-with-paper-trail 224 | def revert 225 | @update_span = params[:update] 226 | @object = referenced_object 227 | if current_user.role? :superadmin 228 | @version = PaperTrail::Version.find(params[:id]) 229 | @version.reify.save! 230 | @object = @Klass.find(@version.item_id) 231 | authorize!(:revert, @object) if cancan_enabled? 232 | respond_to do |format| 233 | format.html { } unless @Klass.not_accessible_through_html? 234 | format.js { render :close } 235 | end 236 | end 237 | end 238 | 239 | def extract_translations 240 | keys_array = [] 241 | I18n::Backend::ActiveRecord::Translation.order(:locale, :thekey).each do |t| 242 | keys_array << deep_hashify([ t.locale, t.thekey.split('.'), t.value ].flatten) 243 | end 244 | keys_hash = {} 245 | keys_array.each do |h| 246 | keys_hash = deep_merge(keys_hash, h) 247 | end 248 | @display_array = unravel(keys_hash) 249 | end 250 | 251 | private 252 | # Get the class from the controller name. 253 | # CountryController < InlineFormsController, so what class are we? 254 | # TODO think about this a bit more. 255 | def getKlass #:doc: 256 | @Klass = self.controller_name.classify.constantize 257 | @Klass 258 | end 259 | 260 | def referenced_object 261 | @Klass.find(object_id_params) 262 | end 263 | 264 | def object_id_params 265 | params.require(:id) 266 | end 267 | 268 | def deep_hashify(ary) 269 | return ary.to_s if ary.length == 1 270 | { ary.shift => deep_hashify(ary) } 271 | end 272 | 273 | def deep_merge(h1, h2) 274 | return h1.merge(h2) unless h2.first[1].is_a? Hash 275 | h1.merge(h2){|key, first, second| deep_merge(first, second)} 276 | end 277 | 278 | def unravel(deep_hash, level=-1) 279 | level += 1 280 | return "#{' '*level}\"#{deep_hash.first[0]}\": \"#{deep_hash.first[1]}\"\n" unless deep_hash.first[1].is_a? Hash 281 | a = "#{' '*level}\"#{deep_hash.first[0]}\":\n" 282 | deep_hash.first[1].each do |k,v| 283 | a << unravel( { k => v}, level) 284 | end 285 | a 286 | end 287 | 288 | def revert_params 289 | params.require(:id).permit(:update) 290 | end 291 | 292 | end 293 | -------------------------------------------------------------------------------- /app/helpers/form_elements/absence_list.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | #InlineForms::SPECIAL_COLUMN_TYPES[:absence_list]=:no_migration 3 | 4 | # checklist 5 | def absence_list_show(object, attribute) # the object is the lesson, attribute should be absences??? 6 | absence_status = { 1 => 'aanwezig', 3 => 'laat met reden', 4 => 'laat' , 5 => 'afwezig met reden', 6 => 'afwezig' } 7 | out = '' 24 | out.html_safe 25 | end 26 | 27 | def absence_list_edit(object, attribute) 28 | # object.send(attribute).build if object.send(attribute).empty? 29 | # values = object.send(attribute).first.class.name.constantize.find(:all) # TODO bring order 30 | out = '
' 31 | out << '' 38 | out << '
' 39 | out.html_safe 40 | end 41 | 42 | # def absence_list_update(object, attribute) 43 | # params[attribute] ||= {} 44 | # object.send(attribute.singularize + '_ids=', params[attribute].keys) 45 | # end 46 | -------------------------------------------------------------------------------- /app/helpers/form_elements/audio_field.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:audio_field]=:string 3 | 4 | def audio_field_show(object, attribute) 5 | o = object.send(attribute) 6 | msg = "".html_safe 7 | if o.send(:present?) 8 | if o.respond_to? :palm 9 | audio_html = audio_tag(o.send(:palm).send(:url), autoplay: false, controls: true) 10 | else 11 | audio_html = audio_tag(o.send(:url), autoplay: false, controls: true) 12 | end 13 | end 14 | link_to_edit = link_to_inline_edit object, attribute, msg 15 | if cancan_disabled? || ( can? :update, object, attribute ) 16 | "#{audio_html} #{link_to_edit}".html_safe 17 | else 18 | audio_html.html_safe 19 | end 20 | end 21 | 22 | def audio_field_edit(object, attribute) 23 | file_field_tag attribute, class: 'input_text_field' 24 | end 25 | 26 | def audio_field_update(object, attribute) 27 | object.send(attribute.to_s + '=', params[attribute.to_sym]) 28 | end 29 | -------------------------------------------------------------------------------- /app/helpers/form_elements/check_box.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:check_box]=:boolean 3 | # boolean, bit unaptly named check_box 4 | def check_box_show(object, attribute) 5 | values = attribute_values(object, attribute) 6 | link_to_inline_edit object, attribute, values[object.send(attribute) ? 1 : 0 ][1] 7 | end 8 | 9 | def check_box_edit(object, attribute) 10 | check_box_tag attribute.to_s, 1, object.send(attribute) 11 | end 12 | 13 | def check_box_update(object, attribute) 14 | object[attribute.to_s.to_sym] = params[attribute.to_s.to_sym].nil? ? 0 : 1 15 | end 16 | 17 | -------------------------------------------------------------------------------- /app/helpers/form_elements/check_list.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:check_list]=:no_migration 3 | 4 | # checklist 5 | def check_list_show(object, attribute) 6 | out = '' 7 | out = link_to_inline_edit(object, attribute, "".html_safe) if object.send(attribute).empty? 8 | object.send(attribute).sort.each do | item | 9 | out << "
" 10 | out << link_to_inline_edit(object, attribute, item._presentation ) 11 | out << '
' 12 | end 13 | out.html_safe 14 | end 15 | 16 | def check_list_edit(object, attribute) 17 | object.send(attribute).build if object.send(attribute).empty? 18 | if cancan_enabled? 19 | values = object.send(attribute).first.class.name.constantize.accessible_by(current_ability).order(attribute.to_s.singularize.camelcase.constantize.order_by_clause) 20 | else 21 | values = object.send(attribute).first.class.name.constantize.order(attribute.to_s.singularize.camelcase.constantize.order_by_clause) 22 | end 23 | out = '' 24 | values.each do | item | 25 | out << "
" 26 | out << check_box_tag( attribute.to_s + '[' + item.id.to_s + ']', 1, object.send(attribute.to_s.singularize + "_ids").include?(item.id) ) 27 | out << "" 28 | out << '
' 29 | end 30 | out.html_safe 31 | end 32 | 33 | def check_list_update(object, attribute) 34 | params[attribute] ||= {} 35 | object.send(attribute.to_s.singularize + '_ids=', params[attribute].keys) 36 | object.touch unless object.new_record? # Check for new_record needed for Rails > 3; TODO we should have a flag to turn this on or of. 37 | end 38 | -------------------------------------------------------------------------------- /app/helpers/form_elements/chicas_dropdown_with_family_members.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:dropdown]=:belongs_to 3 | 4 | # dropdown 5 | def chicas_dropdown_with_family_members_show(object, attribute) 6 | attribute_value = object.send(attribute)._dropdown_presentation rescue "".html_safe 7 | link_to_inline_edit object, attribute, attribute_value 8 | end 9 | 10 | def chicas_dropdown_with_family_members_edit(object, attribute) 11 | o = object.send(attribute) # the client 12 | values = o.family.clients 13 | values.sort_by(&:_dropdown_presentation) 14 | # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form! 15 | collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_s.foreign_key.to_sym, values, 'id', '_dropdown_presentation', :selected => object.send(attribute).id) 16 | end 17 | 18 | def chicas_dropdown_with_family_members_update(object, attribute) 19 | foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.to_s.foreign_key.to_sym 20 | old_path = File.dirname(object.image.path) 21 | object[foreign_key] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_s.foreign_key.to_sym] 22 | if object.save 23 | # move to new location 24 | new_path = File.join(Rails.root, "public/uploads/client/photo/#{object.client_id}") 25 | system "mkdir -vp #{new_path}" 26 | system "mv -v #{old_path} #{new_path}" 27 | end 28 | end 29 | 30 | -------------------------------------------------------------------------------- /app/helpers/form_elements/chicas_family_photo_list.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | # not needed here, since this is only used in the views InlineForms::SPECIAL_COLUMN_TYPES[:info]=:string 3 | 4 | # this will NOT stay in inline_forms, it belongs in an app. 5 | 6 | def chicas_family_photo_list_show(object, attribute) 7 | # the attribute should be like members_photos 8 | # then it will look for object.family.members.photos 9 | # I know it's crappy. 10 | members, photos = attribute.to_s.split('_') 11 | photo_list = {} 12 | object.family.send(members).each do |member| 13 | member.send(photos).each do |photo| 14 | photo_list[photo.rating] ||= [] 15 | photo_list[photo.rating] << photo 16 | end 17 | end 18 | out = '' 19 | if photo_list.empty? 20 | out = "
no photos
" 21 | else 22 | out << "
" 23 | photo_list.sort.reverse.each do |rating, photos| 24 | photos.each do |photo| 25 | out << image_tag(photo.image.url(:thumb), 26 | onclick: "this.src='#{photo.image.url(:palm)}'", 27 | onmouseout: "this.src='#{photo.image.url(:thumb)}'", 28 | alt: photo.name, 29 | title: photo.name) 30 | end 31 | end 32 | out << '
' 33 | end 34 | out.html_safe 35 | end 36 | -------------------------------------------------------------------------------- /app/helpers/form_elements/chicas_photo_list.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | # not needed here, since this is only used in the views InlineForms::SPECIAL_COLUMN_TYPES[:info]=:string 3 | 4 | # this will NOT stay in inline_forms, it belongs in an app. 5 | 6 | def chicas_photo_list_show(object, attribute) 7 | # the attribute should be like members_photos 8 | # then it will look for object.members.photos 9 | # I know it's crappy. 10 | members, photos = attribute.to_s.split('_') 11 | photo_list = {} 12 | object.send(members).each do |member| 13 | member.send(photos).each do |photo| 14 | photo_list[photo.rating] ||= [] 15 | photo_list[photo.rating] << photo 16 | end 17 | end 18 | out = '' 19 | if photo_list.empty? 20 | out = "
no photos
" 21 | else 22 | out << "
" 23 | photo_list.sort.reverse.each do |rating, photos| 24 | photos.each do |photo| 25 | out << image_tag(photo.image.url(:thumb), 26 | onclick: "this.src='#{photo.image.url(:palm)}'", 27 | onmouseout: "this.src='#{photo.image.url(:thumb)}'", 28 | alt: photo.name, 29 | title: photo.name) 30 | end 31 | end 32 | out << '
' 33 | end 34 | out.html_safe 35 | end 36 | -------------------------------------------------------------------------------- /app/helpers/form_elements/ckeditor.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:ckeditor]=:text 3 | 4 | def ckeditor_show(object, attribute) 5 | link_to_inline_edit object, 6 | attribute, 7 | '
'.html_safe + 8 | cktext_area_tag( 9 | attribute, 10 | object[attribute], 11 | :id => "textarea_#{object.class.name.underscore}_#{object.id}_#{attribute.to_s}", 12 | :ckeditor => { :width => '100%', 13 | :height => '200px', 14 | :toolbar => "None", 15 | :readOnly => "true", 16 | :resize_enabled => "false", 17 | :toolbarCanCollapse => "false" 18 | } 19 | ) + 20 | image_tag( 'inline_forms/glass_plate.gif', 21 | :class => "glass_plate", 22 | :title => '' ) + 23 | "".html_safe + 24 | '
'.html_safe 25 | end 26 | 27 | def ckeditor_edit(object, attribute) 28 | cktext_area_tag( attribute, 29 | object[attribute], 30 | :id => "textarea_#{object.class.name.underscore}_#{object.id}_#{attribute.to_s}", 31 | :ckeditor => { :width => '100%', 32 | :height => '200px' 33 | } 34 | ) + 35 | "".html_safe 36 | end 37 | 38 | def ckeditor_update(object, attribute) 39 | object[attribute.to_sym] = params[attribute.to_sym] 40 | end 41 | -------------------------------------------------------------------------------- /app/helpers/form_elements/date.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:date_select]=:date 3 | 4 | # date 5 | def date_select_show(object, attribute) 6 | link_to_inline_edit object, attribute, object.send(attribute).nil? ? "".html_safe : object.send(attribute).to_date.strftime("%d-%m-%Y") 7 | end 8 | 9 | def date_select_edit(object, attribute) 10 | css_id = 'datepicker_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + attribute.to_s 11 | out = text_field_tag attribute, ( object.send(attribute).nil? ? "" : object.send(attribute).to_date.strftime("%d-%m-%Y") ), :id => css_id, :class =>'datepicker' 12 | out << "".html_safe 13 | end 14 | 15 | def date_select_update(object, attribute) 16 | object[attribute.to_sym] = params[attribute.to_sym] 17 | end 18 | 19 | def date_select_info(object, attribute) 20 | object.send(attribute).nil? ? "-" : object.send(attribute).to_date 21 | end 22 | -------------------------------------------------------------------------------- /app/helpers/form_elements/decimal_field.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:decimal_field]=:string 3 | 4 | def decimal_field_show(object, attribute) 5 | link_to_inline_edit object, attribute, object[attribute].nil? ? "".html_safe : object[attribute] 6 | end 7 | 8 | def decimal_field_edit(object, attribute) 9 | text_field_tag attribute, (object.send attribute.to_sym), :class => 'input_decimal_field' # for abide: , :required => true 10 | end 11 | 12 | def decimal_field_update(object, attribute) 13 | object.send :write_attribute, attribute.to_sym, params[attribute.to_sym] 14 | end 15 | 16 | -------------------------------------------------------------------------------- /app/helpers/form_elements/devise_password_field.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:devise_password_field]=:string 3 | 4 | def devise_password_field_show(object, attribute) 5 | link_to_inline_edit object, attribute, '' 6 | end 7 | 8 | def devise_password_field_edit(object, attribute) 9 | password_field_tag attribute, '', :class => 'input_devise_password_field' 10 | end 11 | 12 | def devise_password_field_update(object, attribute) 13 | if params[attribute.to_sym].blank? 14 | # nothing happens 15 | else 16 | object.password = params[attribute.to_sym] 17 | end 18 | end 19 | 20 | -------------------------------------------------------------------------------- /app/helpers/form_elements/dns_records.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | def dnsrecords_show(object, attribute) 3 | out = "" 4 | [object.a_records,object.template_a_records].flatten.collect do |r| 5 | out << r.djbdns_line(object.name) + "
" 6 | end 7 | raw out 8 | end 9 | 10 | def dnsrecords_edit(object, attribute) 11 | end 12 | 13 | def dnsrecords_update(object, attribute) 14 | end 15 | 16 | -------------------------------------------------------------------------------- /app/helpers/form_elements/dropdown.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:dropdown]=:belongs_to 3 | 4 | # dropdown 5 | def dropdown_show(object, attribute) 6 | attr = object.send attribute 7 | presentation = "_presentation" 8 | presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation" 9 | attribute_value = object.send(attribute).send(presentation) rescue "".html_safe 10 | link_to_inline_edit object, attribute, attribute_value 11 | end 12 | 13 | def dropdown_edit(object, attribute) 14 | object.send('build_' + attribute.to_s) unless object.send(attribute) # we really need this! 15 | attr = object.send attribute 16 | presentation = "_presentation" 17 | presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation" 18 | klass = object.send(attribute).class 19 | if cancan_enabled? 20 | values = klass.accessible_by(current_ability) 21 | else 22 | values = klass.all 23 | end 24 | options_disabled = nil 25 | if klass.method_defined? :disabled_for_dropdown? 26 | options_disabled = values.map{|v| v.id if v.disabled_for_dropdown?}.compact 27 | end 28 | values.sort_by {|v|v.send presentation} 29 | # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form! 30 | collection_select( ('_' + object.class.to_s.underscore).to_sym, 31 | attribute.to_s.foreign_key.to_sym, 32 | values, 33 | 'id', 34 | presentation, 35 | selected: (object.send(attribute).id rescue nil), 36 | disabled: options_disabled, 37 | ) 38 | end 39 | 40 | def dropdown_update(object, attribute) 41 | foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.to_s.foreign_key.to_sym 42 | object[foreign_key] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_s.foreign_key.to_sym] 43 | end 44 | 45 | def dropdown_info(object, attribute) 46 | attr = object.send attribute 47 | presentation = "_presentation" 48 | presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation" 49 | object.send(attribute).send(presentation) rescue "-" 50 | end 51 | -------------------------------------------------------------------------------- /app/helpers/form_elements/dropdown_with_integers.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:dropdown_with_integers]=:integer 3 | 4 | # dropdown_with_integers generates a dropdown menu 5 | # with the given list of integers as options 6 | # 7 | # values must be a Range or a one-dimensional array of Integers 8 | def dropdown_with_integers_show(object, attribute) 9 | values = attribute_values(object, attribute) 10 | link_to_inline_edit object, attribute, values[object.send(attribute)][1] 11 | end 12 | 13 | def dropdown_with_integers_edit(object, attribute) 14 | # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form! 15 | values = attribute_values(object, attribute) 16 | collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute)) 17 | end 18 | 19 | def dropdown_with_integers_update(object, attribute) 20 | object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym] 21 | end 22 | -------------------------------------------------------------------------------- /app/helpers/form_elements/dropdown_with_other.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:dropdown_with_other]=:belongs_to 3 | 4 | # dropdown 5 | def dropdown_with_other_show(object, attribute) 6 | attribute = attribute.to_s 7 | foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.foreign_key.to_sym 8 | id = object[foreign_key] 9 | if id == 0 10 | attribute_value = object[attribute + '_other'] 11 | attribute_value = "".html_safe if attribute_value.nil? || attribute_value.empty? 12 | else 13 | attribute_value = object.send(attribute)._presentation rescue "".html_safe 14 | end 15 | link_to_inline_edit object, attribute, attribute_value 16 | end 17 | 18 | def dropdown_with_other_edit(object, attribute) 19 | attribute = attribute.to_s 20 | foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.foreign_key.to_sym 21 | o = attribute.camelcase.constantize 22 | values = o.all 23 | values = o.accessible_by(current_ability) if cancan_enabled? 24 | values.each do |v| 25 | v.name = v._presentation 26 | end 27 | # values.sort_by(&:name) 28 | 29 | collection = values.map {|v|[v.name, v.id]} 30 | collection << [object[attribute + '_other'], 0] unless object[attribute + '_other'].nil? || object[attribute + '_other'].empty? 31 | out = '
' 32 | out << select('_' + object.class.to_s.underscore, foreign_key.to_sym, collection, {selected: object[foreign_key.to_sym]}, {id: '_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + foreign_key.to_s}) 33 | out << '
34 | ' 133 | out.html_safe 134 | 135 | 136 | end 137 | 138 | def dropdown_with_other_update(object, attribute) 139 | attribute = attribute.to_s 140 | foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.foreign_key.to_sym 141 | # if there is an attribute attr, then there must be an attribute attr_other 142 | other = params[('_' + object.class.to_s.underscore).to_sym][(attribute + "_other").to_sym] 143 | # see if it matches anything (but we need to look at I18n too! 144 | lookup_model = attribute.camelcase.constantize 145 | name_field = 'name_' + I18n.locale.to_s 146 | name_field = 'name' unless lookup_model.new.respond_to? name_field 147 | puts 'XXXXXXXXXXXXXXXXXXXX ' + name_field.inspect 148 | match = lookup_model.where(name_field.to_sym => other).first # problem if there are dupes! 149 | puts 'XXXXXXXXXXXXXXXXXXXX ' + match.inspect 150 | match.nil? ? object[foreign_key] = 0 : object[foreign_key] = match.id # problem if there is a record with id: 0 ! 151 | match.nil? ? object[attribute + '_other'] = other : object[attribute + '_other'] = nil 152 | end 153 | 154 | -------------------------------------------------------------------------------- /app/helpers/form_elements/dropdown_with_values.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:dropdown_with_values]=:integer 3 | 4 | # dropdown_with_values 5 | def dropdown_with_values_show(object, attribute) 6 | values = attribute_values(object, attribute) 7 | link_to_inline_edit object, attribute, object.send(attribute) ? t(values.assoc(object.send(attribute))[1]) : "".html_safe 8 | end 9 | 10 | def dropdown_with_values_edit(object, attribute) 11 | # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form! 12 | values = attribute_values(object, attribute) 13 | 14 | attributes = @inline_forms_attribute_list || object.inline_forms_attribute_list 15 | options_disabled = attributes.assoc(attribute.to_sym)[4] 16 | 17 | collection_select( ('_' + object.class.to_s.underscore).to_sym, 18 | attribute.to_sym, 19 | values, 'first', 'last', 20 | :selected => object.send(attribute), 21 | disabled: options_disabled, 22 | ) 23 | end 24 | 25 | def dropdown_with_values_update(object, attribute) 26 | object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym] 27 | end 28 | 29 | def dropdown_with_values_info(object, attribute) 30 | values = attribute_values(object, attribute) 31 | t(values.assoc(object.send(attribute))[1]) rescue '-' 32 | end 33 | -------------------------------------------------------------------------------- /app/helpers/form_elements/dropdown_with_values_with_stars.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:dropdown_with_values_with_stars]=:integer 3 | 4 | # dropdown_with_values_with_stars 5 | def dropdown_with_values_with_stars_show(object, attribute) 6 | values = attribute_values(object, attribute) 7 | link_to_inline_edit object, attribute, (object[attribute].nil? || object[attribute] == 0) ? "".html_safe : image_tag(object[attribute].to_s + 'stars.png') 8 | end 9 | def dropdown_with_values_with_stars_edit(object, attribute) 10 | # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form! 11 | values = attribute_values(object, attribute) 12 | collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute)) 13 | end 14 | def dropdown_with_values_with_stars_update(object, attribute) 15 | object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym] 16 | end 17 | -------------------------------------------------------------------------------- /app/helpers/form_elements/file_field.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:file_field]=:string 3 | 4 | def file_field_show(object, attribute) 5 | o = object.send(attribute) 6 | msg = o.to_s 7 | if o.send(:present?) 8 | msg = "replace | #{o.send(:path).gsub(/^.*\//,'')}".html_safe 9 | end 10 | link_to_inline_edit object, attribute, msg 11 | end 12 | 13 | def file_field_edit(object, attribute) 14 | file_field_tag attribute, :class => 'input_text_field' 15 | end 16 | 17 | def file_field_update(object, attribute) 18 | object.send(attribute.to_s + '=', params[attribute.to_sym]) 19 | end 20 | 21 | -------------------------------------------------------------------------------- /app/helpers/form_elements/geo_code_curacao.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:geo_code_curacao]=:string 3 | 4 | # geo_code_curacao 5 | def geo_code_curacao_show(object, attribute) 6 | attribute_value = GeoCodeCuracao.new(object.send(attribute)).presentation rescue nil 7 | link_to_inline_edit object, attribute, attribute_value 8 | end 9 | def geo_code_curacao_edit(object, attribute) 10 | attribute_value = object.send(attribute).presentation rescue nil 11 | out = text_field_tag attribute, attribute_value 12 | out << ''.html_safe 18 | end 19 | 20 | def geo_code_curacao_update(object, attribute) 21 | # extract the geocode 22 | geo_code = params[attribute].scan(/\d\d\d\d\d\d/).first || nil 23 | object[attribute.to_sym] = GeoCodeCuracao.new(geo_code).valid? ? geo_code : nil 24 | end 25 | 26 | -------------------------------------------------------------------------------- /app/helpers/form_elements/header.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | # not needed here, since this is only used in the views InlineForms::SPECIAL_COLUMN_TYPES[:header]=:string 3 | 4 | def header_show(object, attribute) 5 | # show the header which is the translated fake attribute 6 | attribute 7 | end 8 | 9 | def header_edit(object, attribute) 10 | # just show the header 11 | attribute 12 | end 13 | 14 | def header_update(object, attribute) 15 | # do absolutely nothing 16 | end 17 | 18 | -------------------------------------------------------------------------------- /app/helpers/form_elements/image_field.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:image_field]=:string 3 | 4 | def image_field_show(object, attribute) 5 | o = object.send(attribute) 6 | msg = "".html_safe 7 | if o.send(:present?) 8 | if o.respond_to? :palm 9 | msg = image_tag(o.send(:palm).send(:url)) 10 | else 11 | msg = image_tag(o.send(:url)) 12 | end 13 | end 14 | link_to_inline_edit object, attribute, msg 15 | end 16 | 17 | def image_field_edit(object, attribute) 18 | file_field_tag attribute, class: 'input_text_field' 19 | end 20 | 21 | def image_field_update(object, attribute) 22 | object.send(attribute.to_s + '=', params[attribute.to_sym]) 23 | end 24 | 25 | -------------------------------------------------------------------------------- /app/helpers/form_elements/info.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | # not needed here, since this is only used in the views InlineForms::SPECIAL_COLUMN_TYPES[:info]=:string 3 | 4 | def info_show(object, attribute) 5 | # show the attribute. if it's a date/time, make it nicer. If it has a _presentation, show that instead 6 | o = object.send(attribute) 7 | o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time) 8 | o = o._presentation if o.respond_to?(:_presentation) 9 | o 10 | end 11 | 12 | def info_edit(object, attribute) 13 | o = object.send(attribute) 14 | o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time) 15 | o = o._presentation if o.respond_to?(:_presentation) 16 | o 17 | end 18 | 19 | def info_update(object, attribute) 20 | # do absolutely nothing 21 | end 22 | 23 | def info_info(object, attribute) 24 | # show the attribute. if it's a date/time, make it nicer. If it has a _presentation, show that instead 25 | o = object.send(attribute) 26 | o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time) 27 | o = o._presentation if o.respond_to?(:_presentation) 28 | o 29 | end 30 | 31 | 32 | #module ActionView::Helpers::DateHelper 33 | # 34 | # def distance_of_time_in_words_to_now_with_future(from_time, include_seconds = false) 35 | # if from_time > Time.now() 36 | # 'in ' + distance_of_time_in_words_to_now_without_future(from_time, include_seconds) 37 | # else 38 | # distance_of_time_in_words_to_now_without_future(from_time, include_seconds) + ' ago' 39 | # end 40 | # end 41 | # 42 | # alias_method_chain :distance_of_time_in_words_to_now, :future 43 | # 44 | #end 45 | -------------------------------------------------------------------------------- /app/helpers/form_elements/info_list.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | # not needed here, since this is only used in the views InlineForms::SPECIAL_COLUMN_TYPES[:info]=:string 3 | 4 | def info_list_show(object, attribute) 5 | # we would expect 6 | out = '' 7 | out = "
--
" if object.send(attribute).empty? 8 | object.send(attribute).sort.each do | item | 9 | out << "
" 10 | out << item._presentation 11 | out << '
' 12 | end 13 | out.html_safe 14 | end 15 | 16 | def info_list_edit(object, attribute) 17 | # we should raise an error 18 | end 19 | 20 | def info_list_update(object, attribute) 21 | # we should raise an errror 22 | end 23 | -------------------------------------------------------------------------------- /app/helpers/form_elements/integer_field.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:integer_field]=:integer 3 | 4 | def integer_field_show(object, attribute) 5 | link_to_inline_edit object, attribute, object[attribute].nil? ? "".html_safe : object[attribute] 6 | end 7 | 8 | def integer_field_edit(object, attribute) 9 | number_field_tag attribute, (object.send attribute.to_sym), :class => 'input_integer_field' # for abide: , :required => true 10 | end 11 | 12 | def integer_field_update(object, attribute) 13 | object.send :write_attribute, attribute.to_sym, params[attribute.to_sym] 14 | end 15 | 16 | -------------------------------------------------------------------------------- /app/helpers/form_elements/kansen_slider.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:kansen_slider]=:integer 3 | 4 | # kansen_slider 5 | def kansen_slider_show(object, attribute) 6 | values = attribute_values(object, attribute) 7 | value = object.send(attribute).to_i # should be an int 8 | display_value = values.assoc(value)[1] # values should be [ [ 0, value ], [ 3, value2 ] .... ] and we lookup the key, not the place in the array! 9 | css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}" 10 | if value == 0 || value > 5 11 | out = display_value 12 | else 13 | out = "
".html_safe 14 | out << "
#{display_value}
".html_safe 15 | out << "
".html_safe 16 | out << "".html_safe 17 | out << ('').html_safe 31 | out << "
".html_safe 32 | end 33 | link_to_inline_edit object, attribute, out 34 | end 35 | 36 | def kansen_slider_edit(object, attribute) 37 | # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form! 38 | values = attribute_values(object, attribute) 39 | value = object.send(attribute).to_i # should be an int, will be 0 if nil 40 | css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}" 41 | display_value = values.assoc(value)[1] # values should be [ [ 0, value ], [ 3, value2 ] .... ] and we lookup the key, not the place in the array! 42 | out = "
".html_safe 43 | out << "
#{display_value}
".html_safe 44 | out << "
".html_safe 45 | out << "".html_safe 46 | out << ('').html_safe 65 | out << '
'.html_safe 66 | out 67 | end 68 | 69 | def kansen_slider_update(object, attribute) 70 | object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym] 71 | end 72 | 73 | # 76 | # 77 | # 78 | # 79 | #
80 | # 81 | #

82 | # 83 | # 84 | #

85 | # 86 | #
87 | # 88 | #
89 | # 90 | -------------------------------------------------------------------------------- /app/helpers/form_elements/money_field.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:money_field]=:integer 3 | 4 | def money_field_show(object, attribute) 5 | link_to_inline_edit object, attribute, humanized_money_with_symbol(object.send attribute) 6 | end 7 | 8 | def money_field_edit(object, attribute) 9 | text_field_tag attribute, (object.send attribute), :class => 'input_money_field' 10 | end 11 | 12 | def money_field_update(object, attribute) 13 | object.send( "#{attribute}=", params[attribute]) 14 | end 15 | 16 | -------------------------------------------------------------------------------- /app/helpers/form_elements/month_select.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:month_select]=:integer 3 | 4 | # date 5 | def month_select_show(object, attribute) 6 | link_to_inline_edit object, attribute, (1..12).include?(object[attribute]) ? I18n.localize(Date.new(1970,object[attribute],1), :format => '%B') : "".html_safe 7 | end 8 | 9 | def month_select_edit(object, attribute) 10 | select_month( (1..12).include?(object[attribute]) ? Date.new(1970, object[attribute], 1) : Date.today, field_name: attribute ) 11 | # ( object.send(attribute).nil? ? "" : object.send(attribute).strftime("%d-%m-%Y") ), :id => css_id, :class =>'datepicker' 12 | end 13 | 14 | def month_select_update(object, attribute) 15 | object[attribute.to_sym] = params['date'][attribute] rescue 0 16 | end 17 | -------------------------------------------------------------------------------- /app/helpers/form_elements/month_year_picker.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:month_year_picker]=:date 3 | 4 | # date 5 | def month_year_picker_show(object, attribute) 6 | link_to_inline_edit object, attribute, object.send(attribute).nil? ? "".html_safe : object.send(attribute).strftime("%B %Y") 7 | end 8 | 9 | def month_year_picker_edit(object, attribute) 10 | css_id = 'datepicker_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + attribute.to_s 11 | out = text_field_tag attribute, ( object.send(attribute).nil? ? "" : object.send(attribute).strftime("%B %Y") ), :id => css_id, :class =>'datepicker' 12 | #out << (hidden_field_tag "hidden_" + attribute.to_s, ( object.send(attribute).nil? ? "" : object.send(attribute).strftime("%d-%m-%Y") ), :id => "hiddden_" + css_id) 13 | # http://jsfiddle.net/bopperben/DBpJe/ 14 | out << "".html_safe 26 | end 27 | 28 | def month_year_picker_update(object, attribute) 29 | puts 'XXXXXXXXXXXXXXXXXXXXXXXXXX' + object[attribute.to_sym].inspect 30 | puts 'XXXXXXXXXXXXXXXXXXXXXXXXXX' + Date.parse(params[attribute.to_sym].to_s).strftime("%F").to_s 31 | object[attribute.to_sym] = Date.parse(params[attribute.to_sym].to_s).strftime("%F").to_s 32 | puts 'XXXXXXXXXXXXXXXXXXXXXXXXXX' + object[attribute.to_sym].inspect 33 | end 34 | -------------------------------------------------------------------------------- /app/helpers/form_elements/move.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | #InlineForms::SPECIAL_COLUMN_TYPES[:text_field]=:string 3 | 4 | def move_show(object, attribute) 5 | link_to_inline_edit object, attribute, "".html_safe 6 | end 7 | 8 | def move_edit(object, attribute) 9 | values = object.class.send :hash_tree_to_collection 10 | select( ('_' + object.class.to_s.underscore).to_sym, attribute, values, :selected => object.id ) 11 | end 12 | 13 | def move_update(object, attribute) 14 | target = object.class.find_by_id(params['_' + object.class.to_s.underscore][attribute.to_sym]) 15 | target.add_child(object) 16 | end 17 | 18 | -------------------------------------------------------------------------------- /app/helpers/form_elements/multi_image_field.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:multi_image_field]=:string 3 | 4 | def multi_image_field_show(object, attribute) 5 | o = object.send(attribute) 6 | msg = "".html_safe 7 | if o.send(:present?) 8 | if o.respond_to? :palm 9 | msg = image_tag(o.send(:palm).send(:url)) 10 | else 11 | msg = image_tag(o.send(:url)) 12 | end 13 | end 14 | link_to_inline_edit object, attribute, msg 15 | end 16 | 17 | def multi_image_field_edit(object, attribute) 18 | file_field_tag attribute, multiple: true, class: 'input_text_field multi_image_field' 19 | end 20 | 21 | def multi_image_field_update(object, attribute) 22 | object.send(attribute.to_s + '=', params[attribute.to_sym]) 23 | end 24 | 25 | -------------------------------------------------------------------------------- /app/helpers/form_elements/pdf_link.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | # not needed here, since this is only used in the views InlineForms::SPECIAL_COLUMN_TYPES[:info]=:string 3 | 4 | def pdf_link_show(object, attribute) 5 | # the attribute is the action 6 | "#{link_to 'preview', "/#{attribute}/#{object.id}", :class => "pdf_preview"} #{link_to 'pdf', "/#{attribute}/#{object.id}.pdf", :class => "pdf_open"}".html_safe 7 | end 8 | 9 | def pdf_link_edit(object, attribute) 10 | o = object.send(attribute) 11 | o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time) 12 | o = o._presentation if o.respond_to?(:_presentation) 13 | o 14 | end 15 | 16 | def pdf_link_update(object, attribute) 17 | # do absolutely nothing 18 | end 19 | 20 | #module ActionView::Helpers::DateHelper 21 | # 22 | # def distance_of_time_in_words_to_now_with_future(from_time, include_seconds = false) 23 | # if from_time > Time.now() 24 | # 'in ' + distance_of_time_in_words_to_now_without_future(from_time, include_seconds) 25 | # else 26 | # distance_of_time_in_words_to_now_without_future(from_time, include_seconds) + ' ago' 27 | # end 28 | # end 29 | # 30 | # alias_method_chain :distance_of_time_in_words_to_now, :future 31 | # 32 | #end 33 | # 34 | -------------------------------------------------------------------------------- /app/helpers/form_elements/plain_text_area.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:plain_text_area]=:text 3 | 4 | def plain_text_area_show(object, attribute) 5 | link_to_inline_edit object, attribute, (object[attribute].nil? || object[attribute].empty?) ? "".html_safe : object[attribute] 6 | end 7 | 8 | def plain_text_area_edit(object, attribute) 9 | text_area_tag attribute, object[attribute], :class => 'attribute_text_area' 10 | end 11 | 12 | def plain_text_area_update(object, attribute) 13 | object[attribute.to_sym] = params[attribute.to_sym] 14 | end 15 | -------------------------------------------------------------------------------- /app/helpers/form_elements/question_list.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | #InlineForms::SPECIAL_COLUMN_TYPES[:question_list]=:no_migration 3 | 4 | # checklist 5 | def question_list_show(object, attribute) 6 | out = '' 14 | out.html_safe 15 | end 16 | 17 | def question_list_edit(object, attribute) 18 | object.send(attribute).build if object.send(attribute).empty? 19 | values = object.send(attribute).first.class.name.constantize.find(:all) # TODO bring order 20 | out = '
' 21 | out << '' 37 | out << '
' 38 | out.html_safe 39 | end 40 | 41 | def question_list_update(object, attribute) 42 | params[attribute] ||= {} 43 | object.send(attribute.singularize + '_ids=', params[attribute].keys) 44 | end 45 | -------------------------------------------------------------------------------- /app/helpers/form_elements/radio_button.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:radio_button]=:integer 3 | # radio buttons are integers in this version 4 | # us like this: 5 | # [ :sex , "gender", :radio_button, { 1 => 'male', 2 => 'female' } ], 6 | 7 | def radio_button_show(object, attribute) 8 | values = attribute_values(object, attribute) 9 | link_to_inline_edit object, attribute, object.send(attribute) ? values.assoc(object.send(attribute))[1] : "" 10 | end 11 | 12 | def radio_button_edit(object, attribute) 13 | out ='' 14 | values = attribute_values(object, attribute) 15 | values.each do |key,value| 16 | out << "
" 17 | out << radio_button_tag(attribute.to_s, key, key == object.send(attribute)) 18 | out << "" 19 | out << '
' 20 | end 21 | out.html_safe 22 | end 23 | 24 | def radio_button_update(object, attribute) 25 | object[attribute.to_s.to_sym] = params[attribute.to_s.to_sym] 26 | end 27 | 28 | -------------------------------------------------------------------------------- /app/helpers/form_elements/scale_with_integers.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:scale_with_integers]=:integer 3 | 4 | # scale_with_integers generates a scale 5 | # with the given list of integers as options 6 | # 7 | # values must be a Range or a one-dimensional array of Integers 8 | # 9 | def scale_with_integers_show(object, attribute) 10 | values = attribute_values(object, attribute) 11 | link_to_inline_edit object, attribute, values[object.send(attribute).to_s] 12 | end 13 | 14 | def scale_with_integers_edit(object, attribute) 15 | # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form! 16 | values = attribute_values(object, attribute) 17 | collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute)) 18 | end 19 | 20 | def scale_with_integers_update(object, attribute) 21 | object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym] 22 | end 23 | 24 | -------------------------------------------------------------------------------- /app/helpers/form_elements/scale_with_values.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:scale_with_values]=:integer 3 | 4 | # scale_with_values generates a scale 5 | # with the given list of values as options 6 | # 7 | # values must be a hash { integer => string, ... } or an one-dimensional array of strings 8 | def scale_with_values_show(object, attribute) 9 | values = attribute_values(object, attribute) 10 | link_to_inline_edit object, attribute, values[object.send(attribute)][1] 11 | end 12 | 13 | def scale_with_values_edit(object, attribute) 14 | # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form! 15 | values = attribute_values(object, attribute) 16 | collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute)) 17 | end 18 | 19 | def scale_with_values_update(object, attribute) 20 | object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym] 21 | end 22 | 23 | -------------------------------------------------------------------------------- /app/helpers/form_elements/simple_file_field.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:simple_file_field]=:string 3 | 4 | def simple_file_field_show(object, attribute) 5 | o = object.send(attribute) 6 | method = attribute_values(object, attribute)[0][1] 7 | if o.send(:present?) 8 | filename = o.to_s 9 | model = object.class.to_s.pluralize.underscore 10 | link_to filename, "/#{model}/#{method}/#{object.id}" # route must exist!! 11 | else 12 | link_to_inline_edit object, attribute, "".html_safe 13 | end 14 | end 15 | 16 | def simple_file_field_edit(object, attribute) 17 | file_field_tag attribute, :class => 'input_text_field' 18 | end 19 | 20 | def simple_file_field_update(object, attribute) 21 | object.send(attribute.to_s + '=', params[attribute.to_sym]) 22 | end 23 | 24 | # You need to add a route to your routes.rb file: 25 | # get '/:model/dl/:id' => 'your_controller#download', :as => 'download' 26 | # and a method to your controller: 27 | # def download 28 | # FIXME -------------------------------------------------------------------------------- /app/helpers/form_elements/slider_with_values.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:slider_with_values]=:integer 3 | 4 | # slider_with_values 5 | def slider_with_values_show(object, attribute) 6 | values = attribute_values(object, attribute) 7 | value = object.send(attribute).to_i # should be an int 8 | display_value = values.assoc(value)[1] # values should be [ [ 0, value ], [ 3, value2 ] .... ] and we lookup the key, not the place in the array! 9 | css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}" 10 | if value == 0 11 | out = "?" # we use this as the 'unknown' value. So in the data, 0 should always be the unknown value. This gives problems with sliders where the real value is 0. 12 | else 13 | out = "".html_safe 14 | out << "
".html_safe 15 | out << "
#{display_value}
".html_safe 16 | out << "
".html_safe 17 | out << "".html_safe 18 | out << ('').html_safe 33 | end 34 | link_to_inline_edit object, attribute, out 35 | end 36 | 37 | def slider_with_values_edit(object, attribute) 38 | # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form! 39 | values = attribute_values(object, attribute) 40 | value = object.send(attribute).to_i # should be an int, will be 0 if nil 41 | css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}" 42 | display_value = values.assoc(value)[1] # values should be [ [ 0, value ], [ 3, value2 ] .... ] and we lookup the key, not the place in the array! 43 | out = "".html_safe 44 | out << "
".html_safe 45 | out << "
#{display_value}
".html_safe 46 | out << "
".html_safe 47 | out << "".html_safe 48 | out << ('').html_safe 68 | out 69 | end 70 | 71 | def slider_with_values_update(object, attribute) 72 | object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym] 73 | end 74 | 75 | # 78 | # 79 | # 80 | # 81 | #
82 | # 83 | #

84 | # 85 | # 86 | #

87 | # 88 | #
89 | # 90 | #
91 | # 92 | -------------------------------------------------------------------------------- /app/helpers/form_elements/text_area.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:text_area]=:text 3 | 4 | def text_area_show(object, attribute) 5 | if object.send(attribute).blank? 6 | link_to_inline_edit object, attribute, "".html_safe 7 | else 8 | if defined? Ckeditor 9 | link_to_inline_edit object, 10 | attribute, 11 | '
'.html_safe + 12 | cktext_area_tag( 13 | attribute, 14 | object[attribute], 15 | :id => "textarea_#{object.class.name.underscore}_#{object.id}_#{attribute.to_s}", 16 | :ckeditor => { :width => '100%', 17 | :height => '200px', 18 | :toolbar => "None", 19 | :readOnly => "true", 20 | :resize_enabled => "false", 21 | :toolbarCanCollapse => "false" 22 | } 23 | ) + 24 | image_tag( 'inline_forms/glass_plate.gif', 25 | :class => "glass_plate", 26 | :title => '' ) + 27 | "".html_safe + 28 | '
'.html_safe 29 | else 30 | link_to_inline_edit object, attribute, object[attribute] 31 | end 32 | end 33 | end 34 | 35 | def text_area_edit(object, attribute) 36 | if defined? Ckeditor 37 | cktext_area_tag( 38 | attribute, 39 | object[attribute], 40 | :id => "textarea_#{object.class.name.underscore}_#{object.id}_#{attribute.to_s}", 41 | :ckeditor => { :width => '100%', 42 | :height => '200px' 43 | } 44 | ) + 45 | "".html_safe 46 | else 47 | text_area_tag attribute, object[attribute], :class => 'attribute_text_area' 48 | end 49 | end 50 | 51 | def text_area_update(object, attribute) 52 | object[attribute.to_sym] = params[attribute.to_sym] 53 | end 54 | 55 | def text_area_info(object, attribute) 56 | object[attribute] 57 | end 58 | -------------------------------------------------------------------------------- /app/helpers/form_elements/text_area_without_ckeditor.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:text_area_without_ckeditor]=:text 3 | 4 | def text_area_without_ckeditor_show(object, attribute) 5 | link_to_inline_edit object, attribute, (object[attribute].nil? || object[attribute].empty?) ? "".html_safe : object[attribute] 6 | end 7 | 8 | def text_area_without_ckeditor_edit(object, attribute) 9 | text_area_tag attribute, object[attribute], :class => 'attribute_text_area' 10 | end 11 | 12 | def text_area_without_ckeditor_update(object, attribute) 13 | object[attribute.to_sym] = params[attribute.to_sym] 14 | end 15 | 16 | def text_area_without_ckeditor_info(object, attribute) 17 | object[attribute] 18 | end 19 | -------------------------------------------------------------------------------- /app/helpers/form_elements/text_field.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:text_field]=:string 3 | 4 | def text_field_show(object, attribute) 5 | link_to_inline_edit object, attribute, object[attribute].blank? ? "".html_safe : object[attribute] 6 | end 7 | 8 | def text_field_edit(object, attribute) 9 | text_field_tag attribute, (object.send attribute.to_sym), :class => 'input_text_field' # for abide: , :required => true 10 | end 11 | 12 | def text_field_update(object, attribute) 13 | object.send :write_attribute, attribute.to_sym, params[attribute.to_sym] 14 | end 15 | 16 | def text_field_info(object, attribute) 17 | object[attribute] 18 | end 19 | -------------------------------------------------------------------------------- /app/helpers/form_elements/time.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | InlineForms::SPECIAL_COLUMN_TYPES[:time_select]=:time 3 | 4 | # time 5 | def time_select_show(object, attribute) 6 | link_to_inline_edit object, attribute, object.send(attribute).nil? ? "".html_safe : object.send(attribute).to_datetime.strftime("%l:%M%P") 7 | end 8 | 9 | def time_select_edit(object, attribute) 10 | css_id = 'timepicker_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + attribute.to_s 11 | out = text_field_tag attribute, ( object.send(attribute).nil? ? "" : object.send(attribute).to_datetime.strftime("%l:%M%P") ), :id => css_id, :class =>'timepicker' 12 | out << "".html_safe 13 | end 14 | 15 | def time_select_update(object, attribute) 16 | object[attribute.to_sym] = params[attribute.to_sym] 17 | end 18 | 19 | def time_select_info(object, attribute) 20 | object.send(attribute).nil? ? "-" : object.send(attribute).to_date 21 | end 22 | 23 | -------------------------------------------------------------------------------- /app/helpers/inline_forms_helper.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | module InlineFormsHelper 3 | # load form elements. Each element goes into a separate file 4 | # and defines a _show, _edit and _update method. 5 | # 6 | INLINE_FORMS_PATH = File.dirname(__FILE__) + "/form_elements/" 7 | Dir[INLINE_FORMS_PATH + "*.rb"].each do |form_element| 8 | require form_element 9 | end 10 | 11 | def inline_forms_version 12 | InlineForms::VERSION 13 | end 14 | 15 | private 16 | 17 | def validation_hints_as_list_for(object, attribute) 18 | object.has_validations? ? content_tag(:ul, object.hints.full_messages_for(attribute).map { |m| content_tag(:li, m ) }.join.html_safe ) : "" 19 | end 20 | 21 | # close link 22 | def close_link( object, update_span, html_class = 'button close_button' ) 23 | link_to "".html_safe, 24 | send( object.class.to_s.underscore + '_path', 25 | object, 26 | :update => update_span, 27 | :close => true ), 28 | :remote => true, 29 | :class => html_class, 30 | :title => t('inline_forms.view.close') 31 | end 32 | 33 | # delete link. Mind the difference between delete and destroy. 34 | def link_to_soft_delete( object, update_span ) 35 | soft='' 36 | if (object.soft_deletable? rescue false) 37 | if object.deleted? && (cancan_disabled? || ( can? :soft_restore, object )) 38 | soft = link_to "".html_safe, 39 | send( 'soft_restore_' + object.class.to_s.underscore + '_path', 40 | object, 41 | :update => update_span ), 42 | :method => :post, 43 | :remote => true, 44 | :title => t('inline_forms.view.undelete') 45 | elsif !object.deleted? && (cancan_disabled? || ( can? :soft_delete, object )) 46 | soft = link_to "".html_safe, 47 | send( 'soft_delete_' + object.class.to_s.underscore + '_path', 48 | object, 49 | :update => update_span ), 50 | :method => :post, 51 | :remote => true, 52 | :title => t('inline_forms.view.trash') 53 | end 54 | end 55 | soft.html_safe 56 | end 57 | 58 | # destroy link. Mind the difference between delete and destroy. 59 | def link_to_destroy( object, update_span ) 60 | hard='' 61 | if cancan_disabled? || ( can? :destroy, object ) 62 | hard = link_to "  ".html_safe, 63 | send( object.class.to_s.underscore + '_path', 64 | object, 65 | :update => update_span ), 66 | :method => :delete, 67 | :remote => true, 68 | :title => t('inline_forms.view.trash') 69 | end 70 | hard.html_safe 71 | end 72 | 73 | # new link 74 | def link_to_new_record(model, path_to_new, update_span, parent_class = nil, parent_id = nil, html_class = 'button new_button') 75 | out = (link_to "".html_safe, 76 | send(path_to_new, 77 | :update => update_span, 78 | :parent_class => parent_class, 79 | :parent_id => parent_id, 80 | ), 81 | :remote => true, 82 | :class => html_class, 83 | :title => t('inline_forms.view.add_new', :model => model.model_name.human ) 84 | ) 85 | if cancan_enabled? 86 | if can? :create, model 87 | if parent_class.nil? 88 | raw out 89 | else 90 | raw out if can? :update, parent_class.find(parent_id), (model.to_s.tableize) # can update this specific attribute??? https://github.com/CanCanCommunity/cancancan/issues/845 91 | end 92 | end 93 | else 94 | raw out 95 | end 96 | end 97 | 98 | # link to versions list 99 | def link_to_versions_list(path_to_versions_list, object, update_span, html_class = 'button new_button') 100 | if can? :list_versions, object 101 | if defined?(PaperTrail) && object.respond_to?(:versions) 102 | out = (link_to "".html_safe, 103 | send(path_to_versions_list, 104 | object, 105 | :update => update_span, 106 | ), 107 | :remote => true, 108 | :class => html_class, 109 | :title => t('inline_forms.view.list_versions') 110 | ) 111 | raw out 112 | end 113 | end 114 | end 115 | 116 | # close versions list link 117 | def close_versions_list_link(object, update_span, html_class = 'button close_button' ) 118 | link_to "".html_safe, 119 | send('list_versions_' + @object.class.to_s.underscore + "_path", 120 | object, 121 | :update => update_span, 122 | :close => true 123 | ), 124 | :remote => true, 125 | :class => html_class, 126 | :title => t('inline_forms.view.close_versions_list') 127 | end 128 | 129 | # link_to_inline_edit 130 | def link_to_inline_edit(object, attribute, attribute_value='', form_element=nil) 131 | attribute_value = attribute_value.to_s 132 | spaces = attribute_value.length > 40 ? 0 : 40 - attribute_value.length 133 | value = h(attribute_value) + (" " * spaces).html_safe 134 | css_class_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}" 135 | if (cancan_disabled? rescue true) || ( can? :update, object, attribute ) 136 | # some problem with concerns makes this function not available when called direct. FIXME 137 | link_to value, 138 | send( 'edit_' + object.class.to_s.underscore + '_path', 139 | object, 140 | :attribute => attribute.to_s, 141 | :form_element => form_element.nil? ? calling_method.sub(/_[a-z]+$/,'').sub(/block in /,'') : form_element, 142 | :update => css_class_id ), 143 | :remote => true 144 | else 145 | h(attribute_value) 146 | end 147 | end 148 | 149 | # url to other language 150 | def locale_url(request, locale) 151 | subdomains = request.subdomains 152 | # if there are no subdomains, prepend the locale to the domain 153 | return request.protocol + [ locale, request.domain ].join('.') + request.port_string if subdomains.empty? 154 | # if there is a subdomain, find out if it's an available locale and strip it 155 | subdomains.shift if I18n.available_locales.include?(subdomains.first.to_sym) 156 | # if there are no subdomains, prepend the locale to the domain 157 | return request.protocol + [ locale, request.domain ].join('.') + request.port_string if subdomains.empty? 158 | # else return the rest 159 | request.protocol + [ locale, subdomains.join('.'), request.domain ].join('.') + request.port_string 160 | end 161 | 162 | def translated_attribute(object,attribute) 163 | t("activerecord.attributes.#{object.class.name.underscore}.#{attribute}") 164 | # "activerecord.attributes.#{attribute}", 165 | # "attributes.#{attribute}" ] ) 166 | end 167 | 168 | # get the values for an attribute 169 | # 170 | # values should be a Hash { integer => string, ... } 171 | # 172 | # or a one-dimensional array of strings 173 | # 174 | # or a Range 175 | # 176 | def attribute_values(object, attribute) 177 | # if we have a range 1..6 will result in [[0,1],[1,2],[2,3],...,[5,6]] 178 | # or range -3..3 will result in [[0,-3],[1,-2],[2,-1],...,[6,3]] 179 | # if we have an array ['a','d','b'] will result in [[0,'a'],[2,'b'],[1,'d']] (sorted on value) 180 | # if we have a hash { 0=>'a', 2=>'b', 3=>'d' } will result in [[0,'a'],[2,'b'],[3,'d']] (it will keep the index and sort on the index) 181 | # TODO work this out better! 182 | # 2012-01-23 Use Cases 183 | # [ :sex , "sex", :radio_button, { 1 => 'f', 2 => 'm' } ], 184 | # in this case we want the attribute in the database to be 1 or 2. From that attribute, we need to find the value. 185 | # using an array, won't work, since [ 'f', 'm' ][1] would be 'm' in stead of 'f' 186 | # so values should be a hash. BUT since we don't have sorted hashes (ruby 1,.8.7), the order of the values in the edit screen will be random. 187 | # so we DO need an array, and look up by index (or association?). 188 | # [[1,'v'],[2,'m]] and then use #assoc: 189 | # assoc(obj) → new_ary or nil 190 | # Searches through an array whose elements are also arrays comparing obj with the first element of each contained array using obj.==. 191 | # Returns the first contained array that matches (that is, the first associated array), or nil if no match is found. See also Array#rassoc. 192 | # like value=values.assoc(attribute_from_database)[1] (the [1] is needed since the result of #assoc = [1,'v'] and we need the 'v') 193 | # I feel it's ugly but it works. 194 | # 2012-02-09 Use Case slider_with_values 195 | # { 0 => '???', 1 => '--', 2 => '-', 3 => '+-', 4 => '+', 5 => '++' } 196 | # In the dropdown (or the slider) we definately need the order preserverd. 197 | # attribulte_values turns this into 198 | # [ [0,'???'], [1, '--'] .... [5, '++'] ] 199 | 200 | 201 | attributes = @inline_forms_attribute_list || object.inline_forms_attribute_list # if we do this as a form_element, @inline.. is nil!!! 202 | values = attributes.assoc(attribute.to_sym)[3] 203 | raise t("fatal.no_values_defined_in", @Klass, attribute) if values.nil? 204 | if values.is_a?(Hash) 205 | temp = Array.new 206 | values.to_a.each do |k,v| 207 | temp << [ k, t(v) ] 208 | end 209 | values = temp.sort {|a,b| a[0]<=>b[0]} 210 | else 211 | temp = Array.new 212 | values.to_a.each_index do |i| 213 | temp << [ i, t(values.to_a[i]) ] 214 | end 215 | values = temp.sort {|a,b| a[1]<=>b[1]} 216 | end 217 | values 218 | end 219 | 220 | def version_modified_by id 221 | user = User.find_by_id id 222 | user.nil? ? 'Unknown' : user.name 223 | end 224 | 225 | end 226 | 227 | module Kernel 228 | private 229 | # make the current method available 230 | # http://www.ruby-forum.com/topic/75258 231 | # supposedly, this is fixed in 1.9 232 | def this_method 233 | caller[0] =~ /`([^']*)'/ and $1 234 | end 235 | # make the calling method available 236 | # http://www.ruby-forum.com/topic/75258 237 | # supposedly, this is fixed in 1.9 238 | def calling_method 239 | caller[1] =~ /`([^']*)'/ and $1 240 | end 241 | end 242 | -------------------------------------------------------------------------------- /app/models/concerns/inline_forms/soft_deletable.rb: -------------------------------------------------------------------------------- 1 | module InlineForms::SoftDeletable 2 | extend ActiveSupport::Concern 3 | 4 | # you need to put this in the model: 5 | # include InlineForms::SoftDeletable 6 | # enum deleted: { active: 1, deleted: 2 } 7 | 8 | # you need a migration like this: 9 | # class AddDeletedAtColumnToUser < ActiveRecord::Migration[6.0] 10 | # def change 11 | # add_column :users, :deleted_at, :datetime, default: nil 12 | # add_column :users, :deleted, :integer, default: 1 13 | # add_column :users, :deleted_by, :integer, default: nil 14 | # end 15 | # end 16 | 17 | def soft_deletable? 18 | true 19 | end 20 | 21 | def soft_delete(current_user) 22 | self.deleted = 2 23 | self.deleter = current_user 24 | self.deleted_at = Time.current 25 | save 26 | end 27 | 28 | def soft_restore 29 | self.deleted = 1 30 | self.deleted_by = nil 31 | self.deleted_at = nil 32 | save 33 | end 34 | 35 | end 36 | -------------------------------------------------------------------------------- /app/models/geo_code_curacao.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | class GeoCodeCuracao 3 | attr_accessor :street, :neighbourhood, :zone 4 | 5 | class Zone < ActiveRecord::Base 6 | self.table_name = "Zones" 7 | alias_attribute :name, :NAME 8 | end 9 | 10 | class Neighbourhood < ActiveRecord::Base 11 | self.table_name = "Buurten" 12 | alias_attribute :name, :NAME 13 | end 14 | 15 | class Street < ActiveRecord::Base 16 | self.table_name = "Straatcode" 17 | alias_attribute :name, :NAME 18 | end 19 | 20 | def initialize(geo_code_curacao) 21 | return nil if geo_code_curacao.nil? 22 | decoded = geo_code_curacao.to_s.scan(/\d\d/) 23 | zone_code = decoded[0] 24 | neighbourhood_code = decoded[1] 25 | street_code = decoded[2] 26 | self.street = Street.find_by_ZONECODE_and_NBRHCODE_and_STREETCODE(zone_code,neighbourhood_code,street_code) 27 | self.neighbourhood = Neighbourhood.find_by_ZONECODE_and_NBRHCODE(zone_code,neighbourhood_code) if self.street 28 | self.zone = Zone.find_by_ZONECODE(zone_code) if self.street 29 | end 30 | 31 | def valid? 32 | not self.street.nil? 33 | end 34 | 35 | def presentation 36 | "#{street.name}, #{zone.name}" 37 | end 38 | 39 | def self.lookup(term) 40 | street = term.gsub(/\\/, '\&\&').gsub(/'/, "''") 41 | sql = "select CONCAT( CONCAT_WS( ', ', S.NAME, B.NAME, Z.NAME), ' (', LPAD( S.ZONECODE, 2, '0' ), LPAD( S.NBRHCODE, 2, '0' ), LPAD( S.STREETCODE, 2, '0' ), ')' ) 42 | FROM Straatcode S, Buurten B, Zones Z 43 | WHERE 44 | B.RECORDTYPE='NBRHOOD' 45 | AND S.ZONECODE=Z.ZONECODE 46 | AND B.ZONECODE=Z.ZONECODE 47 | AND S.ZONECODE=B.ZONECODE 48 | AND S.NBRHCODE = B.NBRHCODE 49 | AND S.NAME LIKE '#{street}' 50 | ORDER BY S.NAME" 51 | q = [] 52 | ActiveRecord::Base.connection.execute(sql).to_a.each do |r| 53 | q << { :label => r[0] } 54 | end 55 | q.to_json.html_safe 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /app/validators/curacao_id_number_validator.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | class CuracaoIdNumberValidator < ActiveModel::EachValidator 3 | 4 | def validate_each(record, attribute, value) 5 | if value =~ /^[0-9]{10}$/ 6 | year = value[0..3].to_i 7 | month = value[4..5].to_i 8 | day = value[6..7].to_i 9 | number= value[8..9].to_i 10 | begin 11 | DateTime.civil(year, month, day) 12 | rescue ArgumentError 13 | record.errors.add(attribute.to_sym, options[:message] || "not a valid date" ) 14 | end 15 | else 16 | record.errors.add(attribute.to_sym, options[:message] || "is not a number" ) 17 | end 18 | end 19 | 20 | end 21 | 22 | #"moet bestaan uit tien cijfers (bijvoorbeeld 1983040812)." 23 | #"moet een datum zijn." 24 | -------------------------------------------------------------------------------- /app/validators/is_curacao_phone_validator.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | # == usage: 3 | # in your model, add: 4 | # validates :email, :presence => true, :is_email_address => true; 5 | # taken from http://lindsaar.net/2010/1/31/validates_rails_3_awesome_is_true 6 | # (It's probably a fake regex but hey, it looks legit.) 7 | class IsCuracaoPhoneValidator < ActiveModel::EachValidator 8 | 9 | def error_message 10 | "is geen geldig Curaçao telefoon nummer." 11 | end 12 | 13 | def help_message 14 | "Telefoonnummer moet 7 cijfers zijn, bijvoorbeeld 6781256." 15 | end 16 | 17 | def validate_each(record, attribute, value) 18 | unless value =~ /[4-8][0-9]{6}/ 19 | record.errors[attribute] << (options[:message] || error_message ) 20 | end 21 | end 22 | 23 | end 24 | -------------------------------------------------------------------------------- /app/validators/is_email_address_validator.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : binary -*- 2 | # == usage: 3 | # in your model, add: 4 | # validates :email, :presence => true, :is_email_address => true; 5 | # taken from http://lindsaar.net/2010/1/31/validates_rails_3_awesome_is_true 6 | # (It's probably a fake regex but hey, it looks legit.) 7 | class IsEmailAddressValidator < ActiveModel::EachValidator 8 | EmailAddress = begin 9 | qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]' 10 | dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]' 11 | atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' + 12 | '\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+' 13 | quoted_pair = '\\x5c[\\x00-\\x7f]' 14 | domain_literal = "\\x5b(?:#{dtext}|#{quoted_pair})*\\x5d" 15 | quoted_string = "\\x22(?:#{qtext}|#{quoted_pair})*\\x22" 16 | domain_ref = atom 17 | sub_domain = "(?:#{domain_ref}|#{domain_literal})" 18 | word = "(?:#{atom}|#{quoted_string})" 19 | domain = "#{sub_domain}(?:\\x2e#{sub_domain})*" 20 | local_part = "#{word}(?:\\x2e#{word})*" 21 | addr_spec = "#{local_part}\\x40#{domain}" 22 | pattern = /\A#{addr_spec}\z/ 23 | end 24 | 25 | def error_message 26 | "is not a valid email address." 27 | end 28 | 29 | def validate_each(record, attribute, value) 30 | unless value =~ EmailAddress 31 | record.errors[attribute] << (options[:message] || error_message ) 32 | end 33 | end 34 | 35 | end 36 | -------------------------------------------------------------------------------- /app/validators/must_be_a_value_validator.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | # == usage: 3 | # in your model, add: 4 | # validates :sex, :must_be_a_value => true; 5 | # 6 | # this checks against the objects attribute_values 7 | class MustBeAValueValidator < ActiveModel::EachValidator 8 | 9 | def error_message 10 | "is geen geldige keuze." 11 | end 12 | 13 | def help_message 14 | end 15 | 16 | def validate_each(record, attribute, value) 17 | values = attribute_values(record, attribute) 18 | if values.assoc(value).nil? 19 | record.errors[attribute] << (options[:message] || error_message ) 20 | end 21 | end 22 | 23 | protected 24 | def attribute_values(object, attribute) 25 | # if we have a range 1..6 will result in [[0,1],[1,2],[2,3],...,[5,6]] 26 | # or range -3..3 will result in [[0,-3],[1,-2],[2,-1],...,[6,3]] 27 | # if we have an array ['a','d','b'] will result in [[0,'a'],[2,'b'],[1,'d']] (sorted on value) 28 | # if we have a hash { 0=>'a', 2=>'b', 3=>'d' } will result in [[0,'a'],[2,'b'],[3,'d']] (it will keep the index and sort on the index) 29 | # TODO work this out better! 30 | # 2012-01-23 Use Cases 31 | # [ :sex , "sex", :radio_button, { 1 => 'f', 2 => 'm' } ], 32 | # in this case we want the attribute in the database to be 1 or 2. From that attribute, we need to find the value. 33 | # using an array, won't work, since [ 'v', 'm' ][1] would be 'm' in stead of 'v' 34 | # so values should be a hash. BUT since we don't have sorted hashes (ruby 1,.8.7), the order of the values in the edit screen will be random. 35 | # so we DO need an array, and look up by index. 36 | # [[1,'v'],[2,'m]] and then use #assoc: 37 | # assoc(obj) → new_ary or nil 38 | # Searches through an array whose elements are also arrays comparing obj with the first element of each contained array using obj.==. 39 | # Returns the first contained array that matches (that is, the first associated array), or nil if no match is found. See also Array#rassoc. 40 | # like value=values.assoc(attribute_from_database)[1] (the [1] is needed since the result of #assoc = [1,'v'] and we need the 'v') 41 | # I feel it's ugly but it works. 42 | 43 | attributes = @inline_forms_attribute_list || object.inline_forms_attribute_list # if we do this as a form_element, @inline.. is nil!!! 44 | values = attributes.assoc(attribute.to_sym)[3] 45 | raise "No Values defined in #{@Klass}, #{attribute}" if values.nil? 46 | if values.is_a?(Hash) 47 | temp = Array.new 48 | values.to_a.each do |k,v| 49 | temp << [ k, v ] 50 | end 51 | values = temp.sort {|a,b| a[0]<=>b[0]} 52 | else 53 | temp = Array.new 54 | values.to_a.each_index do |i| 55 | temp << [ i, values.to_a[i] ] 56 | end 57 | values = temp.sort {|a,b| a[1]<=>b[1]} 58 | end 59 | values 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /app/views/devise/inline_forms/_content_for_devise_login.html.erb: -------------------------------------------------------------------------------- 1 |

Welcome to inline_forms!

2 | 3 |

4 | Create the file
5 | app/views/devise/inline_forms/_content_for_devise_login.html.erb
6 | and the contents will be displayed here. 7 |

8 |

9 | Change application title, title_for_devise, welcome_for_devise in
10 | config/locales/inline_forms.en.yml
11 |

12 | 13 | -------------------------------------------------------------------------------- /app/views/devise/inline_forms/_content_for_passwords_edit.html.erb: -------------------------------------------------------------------------------- 1 |

Do you want to change your password?

2 |

If you do, just type in your new password and confirm it.

3 | -------------------------------------------------------------------------------- /app/views/devise/inline_forms/_content_for_passwords_new.html.erb: -------------------------------------------------------------------------------- 1 |

No worries!

2 |

3 | We will send you instructions on how to change your password. 4 |

5 |

6 | Just provide your email address and press 'send instructions'! 7 |

8 | -------------------------------------------------------------------------------- /app/views/devise/passwords/_top-bar-and-flash.html.erb: -------------------------------------------------------------------------------- 1 | 13 | 14 |
15 | <% flash = @flash %> 16 | <% flash.each do |name, msg| %> 17 | <%= content_tag :div, msg, :id => "flash_#{name}", :class => 'devise flash' %> 18 | <% end unless flash.blank? %> 19 |
20 | -------------------------------------------------------------------------------- /app/views/devise/passwords/edit.html.erb: -------------------------------------------------------------------------------- 1 | <% @flash = flash %> 2 | <%= render 'top-bar-and-flash' %> 3 | 4 |
5 |
6 |

<%= t('inline_forms.devise.passwords.change_your_password') %>

7 |
8 |
9 | 10 |
11 | 12 |
13 | 14 | <%= form_for(resource, as: resource_name, 15 | url: password_path(resource_name), 16 | html: { method: :put, 17 | id: 'inline_forms_devise_form' 18 | } 19 | ) do |f| %> 20 | 21 | <%= devise_error_messages! %> 22 | <%= f.hidden_field :reset_password_token %> 23 | 24 |
25 |
26 | <% new_password_label = "New password" 27 | new_password_label += " (#{@minimum_password_length} characters minimum)" if @minimum_password_length 28 | %> 29 | <%= f.label :password, new_password_label.html_safe %> 30 | <%= f.password_field :password, autofocus: true, autocomplete: "off" %> 31 |
32 |
33 | 34 |
35 |
36 | <%= f.label :password_confirmation, "Confirm new password" %> 37 | <%= f.password_field :password_confirmation, autocomplete: "off" %> 38 |
39 |
40 | 41 |
42 |
43 | <%= f.submit t('inline_forms.devise.passwords.change_my_password'), class: 'button' %> 44 |
45 |
46 | 47 | <% end %> 48 | 49 |
50 | 51 |
52 | 53 |
54 |
55 |
56 | 57 |
58 | <%= render '/devise/inline_forms/content_for_passwords_edit' %> 59 |
60 | 61 |
62 | 63 | 64 | 65 | 66 |
67 | -------------------------------------------------------------------------------- /app/views/devise/passwords/new.html.erb: -------------------------------------------------------------------------------- 1 | <% @flash = flash %> 2 | <%= render 'top-bar-and-flash' %> 3 | 4 |
5 |
6 |

<%= t('inline_forms.devise.passwords.forgot_your_password') %>

7 |
8 |
9 | 10 |
11 | 12 |
13 | 14 | <%= form_for(resource, as: resource_name, 15 | url: password_path(resource_name), 16 | html: { method: :post, 17 | id: 'inline_forms_devise_form' 18 | } 19 | ) do |f| %> 20 | 21 | <%= devise_error_messages! %> 22 | 23 |
24 |
25 | 26 | <%= f.email_field :email %> 27 |
28 |
29 | 30 |
31 |
32 | <%= f.submit t('inline_forms.devise.passwords.send_me_instructions'), class: 'button' %> 33 |
34 |
35 | 36 | <% end %> 37 | 38 |
39 | 40 |
41 | 42 |
43 |
44 |
45 | 46 |
47 | <%= render '/devise/inline_forms/content_for_passwords_new' %> 48 |
49 | 50 |
51 | 52 | 53 | 54 | 55 |
56 | -------------------------------------------------------------------------------- /app/views/devise/sessions/_flash.html.erb: -------------------------------------------------------------------------------- 1 | <% if !flash.empty? %> 2 |
3 | <% flash.each do |name, msg| %> 4 | <%= content_tag :div, msg, :id => "flash_#{name}", :class => 'devise flash' %> 5 | <% end %> 6 |
7 | <% end %> 8 | -------------------------------------------------------------------------------- /app/views/devise/sessions/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(resource, as: resource_name, 2 | url: session_path(resource_name), 3 | html: { id: 'inline_forms_devise_form' } 4 | ) do |f| %> 5 | 6 |
7 |
8 | 9 | <%= f.email_field :email %> 10 |
11 |
12 | 13 |
14 |
15 | 16 | <%= f.password_field :password %> 17 |
18 |
19 | 20 | <% if devise_mapping.rememberable? -%> 21 |
22 |
23 | <%= f.check_box :remember_me %> 24 |
25 |
26 | <%= f.submit :login, class: 'button' %> 27 |
28 |
29 | <% else %> 30 |
31 |
32 | <%= f.submit :login, class: 'button' %> 33 |
34 |
35 | <% end -%> 36 | 37 | 38 |
39 |
40 | <%= render :partial => "devise/shared/links" %> 41 |
42 |
43 | 44 | <% end %> 45 | -------------------------------------------------------------------------------- /app/views/devise/sessions/_top-bar-and-flash.html.erb: -------------------------------------------------------------------------------- 1 | <%= render 'top-bar' %> 2 | <%= render 'flash' %> 3 | -------------------------------------------------------------------------------- /app/views/devise/sessions/_top-bar.html.erb: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /app/views/devise/sessions/new.html.erb: -------------------------------------------------------------------------------- 1 | <% @flash = flash %> 2 | 3 | <%= render 'top-bar-and-flash' %> 4 | 5 |
6 |
7 |

<%= t('inline_forms.devise.welcome') %>

8 |
9 |
10 | 11 |
12 | 13 |
14 | 15 | <%= render 'form' %> 16 | 17 |
18 | 19 |
20 | 21 |
22 |
23 |
24 | 25 |
26 | <%= render '/devise/inline_forms/content_for_devise_login' %> 27 |
28 | 29 |
30 | 31 |
32 | -------------------------------------------------------------------------------- /app/views/devise/shared/_header_and_errors.html.erb: -------------------------------------------------------------------------------- 1 |
<%= t application_name -%>
2 |
3 | <%= devise_error_messages!.empty? ? t("inline_forms.devise.#{@default_message}") : devise_error_messages! -%> 4 |
5 | -------------------------------------------------------------------------------- /app/views/devise/shared/_links.erb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/views/geo_code_curacao/list_streets.html.erb: -------------------------------------------------------------------------------- 1 | <%= @streets.each { |s| puts s} %> -------------------------------------------------------------------------------- /app/views/geo_code_curacao/list_streets.js.erb: -------------------------------------------------------------------------------- 1 | <%= @streets %> -------------------------------------------------------------------------------- /app/views/inline_forms/_close.html.erb: -------------------------------------------------------------------------------- 1 | <% if cancan_disabled? || ( can? :soft_delete, @object ) %> 2 |
3 | <%= link_to_soft_delete(@object, @update_span) -%> 4 | <%= link_to_destroy(@object, @update_span) -%> 5 |
6 |
7 | <%= link_to h(@object._presentation), send(@object.class.to_s.underscore + "_path", @object, :update => @update_span), :remote => true -%> 8 |
9 | <% else %> 10 |
11 | <%= link_to h(@object._presentation), send(@object.class.to_s.underscore + "_path", @object, :update => @update_span), :remote => true -%> 12 |
13 | <% end %> 14 | -------------------------------------------------------------------------------- /app/views/inline_forms/_edit.html.erb: -------------------------------------------------------------------------------- 1 | <% @BUTTONS_UNDER = [ "text_area", "kansen_slider" ] %> 2 | <%= form_tag send(@object.class.to_s.underscore + '_path', :update => @update_span, 3 | :attribute => @attribute, 4 | :form_element => @form_element, 5 | :sub_id => @sub_id ), 6 | :method => :put, # this is going to the update method! 7 | :multipart => true, 8 | :class => "edit_form", 9 | :abide => true, 10 | :remote => true do -%> 11 |
12 | <% flash.each do |key, value| %> 13 |
14 |
    15 | <% if value.is_a?(Array) %> 16 | <% value.each do |msg| %> 17 |
  • 18 | <%= msg %> 19 |
  • 20 | <% end %> 21 | <% else %> 22 |
  • 23 | <%= value %> 24 |
  • 25 | <% end %> 26 |
27 |
28 | <% end %> 29 |
30 | 31 | <% if @BUTTONS_UNDER.include? @form_element %> 32 |
33 |
34 | <%= send("#{@form_element}_edit", @object, @attribute) %> 35 |
36 |
37 |
38 |
39 |   40 |
41 |
42 | <%= submit_tag "ok", :class => "postfix button"-%> 43 |
44 |
45 | <%= link_to( send( @object.class.to_s.underscore + '_path', :update => @update_span || "field_#{@attribute}_#{@object.id.to_s}", 46 | :attribute => @attribute, 47 | :form_element => @form_element, 48 | :sub_id => @sub_id ), 49 | :method => :get, # this is going to the show method! 50 | :remote => true ) do %> 51 | 52 | <% end %> 53 |
54 |
55 | <% else %> 56 |
57 |
58 | <%= send("#{@form_element}_edit", @object, @attribute) %> 59 |
60 |
61 | <%= submit_tag "ok", :class => "postfix button"-%> 62 |
63 |
64 | <%= link_to( send( @object.class.to_s.underscore + '_path', :update => @update_span || "field_#{@attribute}_#{@object.id.to_s}", 65 | :attribute => @attribute, 66 | :form_element => @form_element, 67 | :sub_id => @sub_id ), 68 | :method => :get, # this is going to the show method! 69 | :remote => true ) do %> 70 | 71 | <% end %> 72 |
73 |
74 | <% end%> 75 | 76 | <% end -%> 77 | -------------------------------------------------------------------------------- /app/views/inline_forms/_flash.html.erb: -------------------------------------------------------------------------------- 1 | <% unless flash.empty? %> 2 | <% identifier = Time.now.to_i.to_s %> 3 |
4 | <% flash.each do |key, value| %> 5 | <%= value %> 6 | <% end %> 7 | 11 |
12 | <% end %> 13 | 14 | -------------------------------------------------------------------------------- /app/views/inline_forms/_header.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 47 |
48 | -------------------------------------------------------------------------------- /app/views/inline_forms/_list.html.erb: -------------------------------------------------------------------------------- 1 | <% ul_needed = true %> 2 | <% pagination = true %> 3 | <% if not defined?(parent_class) %> 4 | <% # we didn't come here via _show.html.erb %> 5 | <% if @parent_class.nil? %> 6 | <% # the controller didn't give us a parent_class, this means we are here for the 'first' time %> 7 | <% # we have to rely on the @Klass set in the controller %> 8 | <% update_span = @Klass.to_s.pluralize.downcase + '_list' %> 9 | <% path_to_new = "new_#{@Klass.to_s.singularize.underscore}_path" %> 10 | <% parent_class = nil %> 11 | <% parent_id = nil %> 12 | <% objects = @objects %> 13 | <% model = @Klass %> 14 | <% else %> 15 | <% # the controller gave us an @parent_class, so ... %> 16 | <% attribute = @Klass.to_s.underscore.pluralize %> 17 | <% update_span = "#{@parent_class.to_s.underscore}_#{@parent_id}_#{attribute}_list" -%> 18 | <% path_to_new='new_' + attribute.to_s.underscore.singularize + '_path' %> 19 | <% parent_class=@parent_class.constantize %> 20 | <% parent_id=@parent_id %> 21 | <% objects = @objects %> 22 | <% ul_needed = false unless @ul_needed %> 23 | <% model = attribute.to_s.singularize.camelcase.constantize %> 24 | <% end %> 25 | <% else %> 26 | <% # here we come from _show %> 27 | <% if form_element == :has_one %> 28 | <% update_span = "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}_list" -%> 29 | <% objects = [ parent_class.find(parent_id).send(attribute) ] %> 30 | <% pagination = false %> 31 | <% else %> 32 | <% update_span = "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}_list" -%> 33 | <% path_to_new='new_' + attribute.to_s.singularize + '_path' %> 34 | <% foreign_key = parent_class.reflect_on_association(attribute.to_sym).options[:foreign_key] || parent_class.name.foreign_key -%> 35 | <% model = attribute.to_s.singularize.camelcase.constantize %> 36 | <% conditions = [ "#{model.table_name}.#{foreign_key} = ?", parent_id ] %> 37 | <% objects = parent_class.find(parent_id).send(attribute) %> 38 | <% objects = parent_class.find(parent_id).send(attribute).accessible_by(current_ability) if cancan_enabled? %> 39 | <% objects = objects.order(attribute.to_s.singularize.camelcase.constantize.order_by_clause) if attribute.to_s.singularize.camelcase.constantize.respond_to?(:order_by_clause) && ! attribute.to_s.singularize.camelcase.constantize.order_by_clause.nil? %> 40 | <% objects = objects.where(conditions).paginate(:page => params[:page]) %> 41 | <% end %> 42 | <% end %> 43 | 44 | <%= raw "
" if ul_needed -%> 45 | 46 | 47 | <% for object in objects %> 48 | <% if parent_class.nil? %> 49 | <% css_class_id = object.class.to_s.underscore + '_' + object.id.to_s -%> 50 | <% path_to_object = object.class.to_s.underscore + '_path' %> 51 | <% else %> 52 | <% css_class_id = parent_class.to_s.underscore + '_' + parent_id.to_s + '_' + attribute.to_s.singularize.underscore + "_" + object.id.to_s -%> 53 | <% path_to_object = attribute.to_s.singularize.underscore + "_path" %> 54 | <% end %> 55 |
" id="<%= css_class_id -%>"> 56 | <% if cancan_disabled? || ( can? :soft_delete, object ) %> 57 |
58 | <%= link_to_soft_delete(object, css_class_id) -%> 59 | <%= link_to_destroy(object, css_class_id) -%> 60 |
61 |
62 | <%= link_to h(object._presentation), 63 | send( path_to_object, object, :update => css_class_id), 64 | :remote => true -%> 65 |
66 | <% else %> 67 |
68 | <%= link_to h(object._presentation), 69 | send( path_to_object, object, :update => css_class_id), 70 | :remote => true -%> 71 |
72 | <% end %> 73 |
74 | <% end -%> 75 | 76 | <% if parent_id.nil? -%> 77 | <% pagination = will_paginate objects -%> 78 | <% else %> 79 | <% if pagination %> 80 | <% pagination = will_paginate objects, :remote => true, :params => {:controller => attribute, :action => :index, :id => nil, :parent_class => parent_class, :parent_id => parent_id, :update => "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}", :ul_needed => true } %> 81 | <% end %> 82 | <% end %> 83 | <% if pagination %> 84 |
85 |
86 | <%= raw pagination %> 87 |
88 |
89 | <% end %> 90 | <%= raw "
" if ul_needed -%> 91 | -------------------------------------------------------------------------------- /app/views/inline_forms/_new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | <% flash.each do |key, value| %> 4 |
5 |
    6 | <% if value.is_a?(Array) %> 7 | <% value.each do |msg| %> 8 |
  • 9 | <%= msg %> 10 |
  • 11 | <% end %> 12 | <% else %> 13 |
  • 14 | <%= value %> 15 |
  • 16 | <% end %> 17 |
18 |
19 | <% end %> 20 |
21 | 22 |
23 |
24 | <%= t('inline_forms.view.add_new', :model => @Klass.model_name.human ) -%> 25 |
26 |
27 | 28 | <%= form_tag send(@Klass.to_s.underscore.pluralize + '_path', :update => @update_span, 29 | :parent_class => @parent_class, 30 | :parent_id => @parent_id ), 31 | :multipart => true, :remote => true, :class => "edit_form" do -%> 32 | <% attributes = @inline_forms_attribute_list || @object.inline_forms_attribute_list -%> 33 | <% attributes.each do | attribute, name, form_element | -%> 34 | <% unless form_element.to_sym == :associated || form_element.to_sym == :tree || (cancan_enabled? && cannot?(:read, @object, attribute)) -%> 35 | <% css_class_id = "attribute_#{attribute}_#{@object.id}" -%> 36 | <% if form_element && form_element.to_sym == :header %> 37 |
38 |
39 | <%= @object.human_attribute_name(attribute) -%> 40 |
41 |
42 | <% else %> 43 |
44 |
45 | <%= @object.human_attribute_name(attribute) -%> 46 |
47 |
48 | <%= send("#{form_element}_edit", @object, attribute) -%> 49 |
50 |
51 | <% end -%> 52 | <% end -%> 53 | <% end -%> 54 |
55 |
56 |   57 |
58 |
59 | <%= link_to( send(@Klass.to_s.underscore.pluralize + '_path', :update => @update_span, 60 | :parent_class => @parent_class, 61 | :parent_id => @parent_id, 62 | :ul_needed => true ), 63 | :remote => true, 64 | ) do -%> 65 | 66 | <% end %> 67 | <%= submit_tag "ok", :class => "button "-%> 68 |
69 |
70 | 71 | <% end %> 72 |
73 | -------------------------------------------------------------------------------- /app/views/inline_forms/_new_nested.html.erb: -------------------------------------------------------------------------------- 1 | This goes in _new.html.erb 2 | <% if form_element.to_sym == :associated -%> 3 | <% @nested_model = @object.send(attribute) %> 4 | <%= render 'new_nested' %> 5 | <% end %> 6 | ******** 7 | 8 | <% @nested_object = @nested_model.build %> 9 | 10 |
11 |
12 |
13 | <%= t('inline_forms.view.add_new', :model => @nested_object.class ) -%> 14 |
15 |
16 | <% nested_attributes = @nested_object.inline_forms_attribute_list -%> 17 | <% nested_attributes.each do | nested_attribute, nested_name, nested_form_element | -%> 18 | <% @nested_form_element = nested_form_element %> 19 | <% @nested_attribute = nested_attribute %> 20 | <% unless @nested_form_element.to_sym == :associated -%> 21 | <% if @nested_form_element == :header %> 22 |
23 |
24 | <%= @nested_object.class.human_attribute_name(@nested_attribute) -%> 25 |
26 |
27 | <% else %> 28 |
29 |
30 | <%= @nested_object.class.human_attribute_name(@nested_attribute) -%> 31 |
32 |
33 | <%= send("#{@nested_form_element}_edit", @nested_object, @nested_attribute) -%> 34 |
35 |
36 | <% end -%> 37 | <% end -%> 38 | <% end -%> 39 | <% if @nested_form_element.to_sym == :associated -%> 40 | <%= render 'new_nested' %> 41 | <% end %> 42 | 43 |
44 | -------------------------------------------------------------------------------- /app/views/inline_forms/_show.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <% if (INLINE_FORMS_SHOW_INDENT rescue true) %> 3 |
4 |   5 |
6 |
7 | <% else %> 8 |
9 | <% end %> 10 | <% unless @skip %> 11 |
12 |
13 | <%= h(@object._presentation) -%> 14 |
15 | 18 |
19 | <% end %> 20 | <% attributes = @inline_forms_attribute_list || @object.inline_forms_attribute_list -%> 21 | <% attributes.each do | attribute, name, form_element | -%> 22 | <% if cancan_disabled? || can?(:read, @object, attribute) %> 23 | <% css_class_id = "#{@object.class.name.underscore}_#{@object.id}_#{attribute}" -%> 24 | <% if form_element == :header %> 25 |
26 |
27 | <%= @object.class.human_attribute_name(attribute) -%> 28 |
29 |
30 | <% else %> 31 | <% if form_element == :tree -%> 32 |
33 |
34 | Children 35 |
36 |
37 | <%= link_to_new_record(@object.class, "new_#{@object.class.to_s.underscore.singularize}_path", css_class_id, @object.class, @object.id) -%> 38 |
39 |
40 |
41 | <% if (INLINE_FORMS_TREE_INDENT rescue true) %> 42 |
43 |   44 |
45 |
46 | <% else %> 47 |
48 | <% end %> 49 | <%= render :partial => "inline_forms/tree", 50 | :locals => { :parent_class => @object.class, 51 | :parent_id => @object.id, 52 | :attribute => attribute } %> 53 |
54 |
55 | <% else %> 56 | <% if form_element == :associated -%> 57 |
58 |
59 | <%= @object.class.human_attribute_name(attribute) -%> 60 |
61 |
62 | <%= link_to_new_record(attribute.to_s.singularize.camelcase.constantize, "new_#{attribute.to_s.underscore.singularize}_path", css_class_id, @object.class, @object.id) -%> 63 |
64 |
65 |
66 | <% if (INLINE_FORMS_ASSOCIATED_INDENT rescue true) %> 67 |
68 |   69 |
70 |
71 | <% else %> 72 |
73 | <% end %> 74 | <%= render :partial => "inline_forms/list", 75 | :locals => { :parent_class => @object.class, 76 | :parent_id => @object.id, 77 | :attribute => attribute, 78 | :form_element => form_element } %> 79 |
80 |
81 | <% else %> 82 | <% if form_element == :has_one %> 83 |
84 |
85 |   86 |
87 |
88 | <%= render :partial => "inline_forms/list", 89 | :locals => { :parent_class => @object.class, 90 | :parent_id => @object.id, 91 | :attribute => attribute, 92 | :form_element => form_element } %> 93 |
94 |
95 | <% else %> 96 |
97 |
98 | <% if @object.has_validations_for?(attribute) -%> 99 | 100 | <%= @object.class.human_attribute_name(attribute) -%> 101 | 102 | <% else %> 103 | <%= @object.class.human_attribute_name(attribute) -%> 104 | <% end %> 105 |
106 |
107 | 108 | <%= send("#{form_element}_show", @object, attribute) -%> 109 | 110 |
111 |
112 | <% end %> 113 | <% end %> 114 | <% end %> 115 | <% end %> 116 | <% end %> 117 | <% end %> 118 | <% if can? :list_versions, @object %> 119 | <% css_class_id = "#{@object.class.name.underscore}_#{@object.id}_versions" -%> 120 |
121 | <%= render 'versions' %> 122 |
123 | <% end %> 124 | 125 |
126 |
127 | -------------------------------------------------------------------------------- /app/views/inline_forms/_tree.html.erb: -------------------------------------------------------------------------------- 1 | <% # here we come from _show %> 2 | <% update_span = "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}_list" -%> 3 | <% path_to_new='new_' + parent_class.to_s.underscore.singularize + '_path' %> 4 | <% model = parent_class %> 5 | <% objects = parent_class.find(parent_id).children %> 6 | <% objects = parent_class.find(parent_id).children.accessible_by(current_ability) if cancan_enabled? %> 7 | <% objects = objects.paginate :page => params[:page] %> 8 | 9 |
10 | 11 | 12 | <% for object in objects %> 13 | <% css_class_id = parent_class.to_s.underscore + '_' + parent_id.to_s + '_' + attribute.to_s.singularize.underscore + "_" + object.id.to_s -%> 14 | <% path_to_object = parent_class.to_s.singularize.underscore + "_path" %> 15 |
" id="<%= css_class_id -%>"> 16 | <% if cancan_disabled? || ( can? :delete, object ) %> 17 |
18 | <%= link_to_destroy(object, css_class_id) -%> 19 |
20 |
21 | <%= link_to h(object._presentation), 22 | send( path_to_object, object, :update => css_class_id), 23 | :remote => true -%> 24 |
25 | <% else %> 26 |
27 | <%= link_to h(object._presentation), 28 | send( path_to_object, object, :update => css_class_id), 29 | :remote => true -%> 30 |
31 | <% end %> 32 |
33 | <% end -%> 34 | 35 | <% if parent_id.nil? -%> 36 | <% pagination = will_paginate objects -%> 37 | <% else %> 38 | <% pagination = will_paginate objects, :remote => true, :params => {:controller => attribute, :action => :index, :id => nil, :parent_class => parent_class, :parent_id => parent_id, :update => "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}", :ul_needed => true } -%> 39 | <% end %> 40 | <% if pagination %> 41 |
42 |
43 | <%= raw pagination %> 44 |
45 |
46 | <% end %> 47 | -------------------------------------------------------------------------------- /app/views/inline_forms/_versions.html.erb: -------------------------------------------------------------------------------- 1 | <% css_class_id = "#{@object.class.name.underscore}_#{@object.id}_versions" -%> 2 |
3 |
4 | <%= "Versions (#{@object.versions.length})" %> 5 |
6 |
7 | <%= link_to_versions_list( 8 | 'list_versions_' + @object.class.to_s.underscore + "_path", 9 | @object, 10 | css_class_id 11 | ) 12 | %> 13 |
14 |
15 | -------------------------------------------------------------------------------- /app/views/inline_forms/_versions_list.html.erb: -------------------------------------------------------------------------------- 1 | <% path_to_object = @object.class.to_s.underscore + '_path' %> 2 | <% css_class_id = "#{@object.class.name.underscore}_#{@object.id}_versions" -%> 3 |
4 |
5 | <%= "Versions (#{@object.versions.length})" %> 6 |
7 |
8 | <%= close_versions_list_link( 9 | @object, 10 | css_class_id 11 | ) 12 | %> 13 |
14 |
15 |
16 |
17 |
18 |   19 |
20 |
21 | Event 22 |
23 |
24 | Done by 25 |
26 |
27 | Changeset 28 |
29 |
30 |
31 |
32 | <% @object.versions.reverse.each do | version | %> 33 |
34 |
35 | <%= link_to t('inline_forms.view.restore'), 36 | send('revert_' + @object.class.to_s.underscore + "_path", 37 | version, 38 | :update => "#{@object.class.name.underscore}_#{@object.id}" 39 | ), 40 | :remote => true, 41 | :method => :post 42 | %> 43 |
44 |
45 | <%= version.event -%> 46 |
47 |
48 | <%= version.created_at -%> 49 |
50 |
51 | <%= version_modified_by version.whodunnit -%> 52 |
53 |
54 | <% if version.changeset.nil? || version.changeset.empty? %> 55 | empty 56 | <% else %> 57 | <% version.changeset.each do |attribute, value| %> 58 | <% next if attribute == 'updated_at' %> 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
<%= attribute %>
old valuenew value
<%= value[0] %><%= value[1] %>
73 | <% end %> 74 | <% end %> 75 |
76 |
77 | <% end %> 78 |
79 | -------------------------------------------------------------------------------- /app/views/inline_forms/close.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').fadeOut("slow", function() { 2 | $(this).html('<%= escape_javascript(render(:partial => 'inline_forms/close' ))%>'); 3 | $(this).fadeIn("slow"); 4 | }); -------------------------------------------------------------------------------- /app/views/inline_forms/edit.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').html('<%= escape_javascript(render(:partial => 'inline_forms/edit' ))%>') 2 | -------------------------------------------------------------------------------- /app/views/inline_forms/extract_translations.erb: -------------------------------------------------------------------------------- 1 | 2 |
3 | <%= @display_array%>
4 | 
-------------------------------------------------------------------------------- /app/views/inline_forms/list.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').html('<%= escape_javascript(render(:partial => 'inline_forms/list' ))%>') 2 | -------------------------------------------------------------------------------- /app/views/inline_forms/new.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').html('<%= escape_javascript(render(:partial => 'inline_forms/new' ))%>') 2 | -------------------------------------------------------------------------------- /app/views/inline_forms/record_destroyed.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').fadeOut("slow") 2 | -------------------------------------------------------------------------------- /app/views/inline_forms/show.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').html('<%= escape_javascript(render(:partial => 'inline_forms/show' ))%>') 2 | -------------------------------------------------------------------------------- /app/views/inline_forms/show_element.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').html('<%= escape_javascript(send("#{@form_element}_show", @object, @attribute))%>') 2 | -------------------------------------------------------------------------------- /app/views/inline_forms/show_undo.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').html('<%= escape_javascript(link_to t('inline_forms.view.undo'), send('revert_' + @object.class.to_s.underscore + "_path", @object.versions.scope.last, :update => @update_span), :remote => true, :method => :post)%>') 2 | -------------------------------------------------------------------------------- /app/views/inline_forms/update.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').html('<%= escape_javascript(send("#{@form_element.to_s}_show", @object, @attribute))%>') 2 | -------------------------------------------------------------------------------- /app/views/inline_forms/versions.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').fadeOut("slow", function() { 2 | $(this).html('<%= escape_javascript(render(:partial => 'inline_forms/versions' ))%>'); 3 | $(this).fadeIn("slow"); 4 | }); 5 | -------------------------------------------------------------------------------- /app/views/inline_forms/versions_list.js.erb: -------------------------------------------------------------------------------- 1 | $('#<%= @update_span %>').html('<%= escape_javascript(render(:partial => 'inline_forms/versions_list' ))%>') 2 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%= t('inline_forms.general.application_title') %> v<%= InlineForms::VERSION %> 8 | 9 | <%= stylesheet_link_tag "application" %> 10 | <%= csrf_meta_tags %> 11 | 12 | 13 | 14 | <%= yield %> 15 | <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> 16 | <%= javascript_include_tag Ckeditor.cdn_url %> 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/views/layouts/devise.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%= t('inline_forms.general.application_title') %> v<%= InlineForms::VERSION %> 8 | 9 | <%= stylesheet_link_tag "inline_forms/devise" %> 10 | <%= stylesheet_link_tag "inline_forms_devise" %> 11 | <%= csrf_meta_tags %> 12 | 13 | 14 | 15 |
16 | <%= yield %> 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /app/views/layouts/inline_forms.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= t('application_name') + " v" + InlineForms::VERSION -%> 7 | <%= stylesheet_link_tag "application" %> 8 | <%= stylesheet_link_tag "inline_forms/inline_forms" %> 9 | <%= csrf_meta_tags %> 10 | 11 | 12 | 13 | <%= render "inline_forms/header" %> 14 | <%= render "/inline_forms_tabs" %> 15 |
16 | <%= yield %> 17 |
18 | <%= javascript_include_tag 'inline_forms/inline_forms', 'data-turbolinks-track' => true %> 19 | <%= javascript_include_tag Ckeditor.cdn_url %> 20 | 21 | 22 | -------------------------------------------------------------------------------- /bin/inline_forms: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | module InlineForms 3 | require File.join(File.dirname(__FILE__), "../lib/inline_forms/version.rb") 4 | require 'securerandom' 5 | 6 | # what is this? 7 | Signal.trap("INT") { puts; exit } 8 | 9 | require 'thor' 10 | class Creator < Thor 11 | include Thor::Actions 12 | 13 | def self.source_root 14 | File.dirname(__FILE__)+"/.." 15 | end 16 | desc "create APP", "create an application with inline_forms v#{VERSION}" 17 | DATABASE_OPTIONS = %w(sqlite mysql) 18 | method_option :database, :aliases => "-d", :banner => DATABASE_OPTIONS.join('|'), :desc => 'specify development database' 19 | method_option :example, :type => :boolean, :desc => 'install the example app. uses sqlite as development database' 20 | method_option :email, :aliases => "-e", :default => "admin@example.com", :desc => 'specify admin email' 21 | method_option :password, :aliases => "-p", :default => "admin999", :desc => 'specify admin password' 22 | method_option :runtest, :aliases => "\-\-run-test", :default => false, :desc => 'run tests' 23 | method_option :skiprvm, :aliases => "\-\-no-rvm", :type => :boolean, :default => false, :desc => 'install inline_forms without RVM' 24 | 25 | def create(app_name) 26 | def self.skiprvm 27 | options[:skiprvm] 28 | end 29 | 30 | def self.runtest 31 | options[:runtest] 32 | end 33 | 34 | def self.install_example? 35 | options[:example] 36 | end 37 | 38 | def self.database 39 | @database ||= options[:database] 40 | return @database if DATABASE_OPTIONS.include?(@database) 41 | say "No Database specified please choose one database #{DATABASE_OPTIONS.join(' | ')}", :red 42 | # if the database is not set ask user which database to use 43 | while ! DATABASE_OPTIONS.include?(@database) 44 | @database = ask "Database: " 45 | return @database if DATABASE_OPTIONS.include?(@database) 46 | end 47 | end 48 | 49 | def self.using_sqlite? 50 | database == 'sqlite' 51 | end 52 | 53 | def self.email 54 | options[:email] 55 | end 56 | 57 | def self.password 58 | options[:password] 59 | end 60 | 61 | if install_example? && !using_sqlite? 62 | say "--example can only be used with an sqlite development database", :red 63 | exit 1 64 | end 65 | 66 | say "Creating #{app_name} with inline_forms v#{VERSION} and development database #{database}...", :green 67 | 68 | regex = /\A[0-9a-zA-Z][0-9a-zA-Z_-]+[0-9a-zA-Z]\Z/ 69 | if ! regex.match(app_name) 70 | say "Error: APP must match #{regex.source}", :red 71 | exit 1 72 | end 73 | 74 | if File.exist?(app_name) 75 | say "Error: APP exists", :red 76 | exit 1 77 | end 78 | 79 | require 'rvm' 80 | # if RVM is detected and the user has not disabled using rvm via command than use rvm else without 81 | if RVM.current && !options[:skiprvm] 82 | # Let the user know that he are installing the inline_forms with support of RVM 83 | say "Installing inline_forms with RVM", :green 84 | # which ruby version is currently activated? 85 | ruby_version = (%x[rvm current]).gsub(/@.*/,'') 86 | # Create a ruby rvm-file version based on the version detected 87 | create_file "#{app_name}/.ruby-version", ruby_version 88 | # Creat a ruby-gemset rvm-file based on the version detected 89 | create_file "#{app_name}/.ruby-gemset", app_name 90 | else 91 | # Let the user know that he is installing inline_forms without RVM 92 | say "Installing inline_forms without RVM", :green 93 | end 94 | 95 | say "Installing with #{options[:database]}", :green 96 | 97 | # Creates the app directory 98 | empty_directory(app_name) 99 | 100 | # puts all options in environment to app_template 101 | options.each do | k,v | 102 | ENV[k] = v.to_s 103 | end 104 | 105 | ENV['using_sqlite'] = using_sqlite?.to_s 106 | ENV['database'] = database 107 | ENV['install_example'] = install_example?.to_s 108 | ENV['ruby_version'] = ruby_version 109 | ENV['inline_forms_version'] = VERSION 110 | 111 | app_template_file = File.join(File.dirname(__FILE__), 'inline_forms_app_template.rb') 112 | 113 | if ! run("rails new #{app_name} -m #{app_template_file} --skip-bundle --skip-gemfile --skip-test-unit --skip-bootsnap") 114 | say "Rails could not create the app '#{app_name}', maybe because it is a reserved word...", :red # TODO ROYTJE MAKE ERROR MESSAGE MORE RELEVANT # Rails could not create the app 'MyApp', maybe because it is a reserved word.. 115 | exit 1 116 | end 117 | end 118 | Creator.start 119 | end 120 | end 121 | -------------------------------------------------------------------------------- /bin/inline_forms_app_template.rb: -------------------------------------------------------------------------------- 1 | require 'rvm' 2 | 3 | if RVM.current && ENV['skiprvm'] !='true' 4 | rvm_version = "#{ENV['ruby_version']}@#{app_name}" 5 | RVM.chdir "../#{app_name}" do 6 | say "Working directory is #{`pwd`}" 7 | RVM.use_from_path! '.' # TODO ROYTJE FIX THIS BELOW 8 | # Warning! PATH is not properly set up, '/home/vagrant/.rvm/gems/ruby-2.0.0-p247@MyApp/bin' is not available, 9 | # usually this is caused by shell initialization files - check them for 'PATH=...' entries, 10 | # it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles', 11 | # to fix temporarily in this shell session run: 'rvm use ruby-2.0.0-p247@MyApp'. 12 | rvm_gemset = %x[rvm current] 13 | say "RVM GEMSET is now #{rvm_gemset}" 14 | say "Installing using gemset : #{RVM.current.environment_name}", :green 15 | end 16 | else 17 | say "Installing without RVM", :green 18 | end 19 | 20 | apply(File.join(File.dirname(__FILE__), 'inline_forms_installer_core.rb')) 21 | -------------------------------------------------------------------------------- /inline_forms.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $:.push File.expand_path("../lib", __FILE__) 3 | require "inline_forms/version" 4 | 5 | Gem::Specification.new do |s| 6 | s.name = "inline_forms" 7 | s.version = InlineForms::VERSION 8 | s.platform = Gem::Platform::RUBY 9 | s.authors = ["Ace Suares", "Lemuel Boyce", "Manuel Ortega"] 10 | s.email = ["ace@suares.com"] 11 | s.homepage = %q{http://github.com/acesuares/inline_forms} 12 | s.summary = %q{Inline editing of forms.} 13 | s.description = %q{Inline Forms aims to ease the setup of forms that provide inline editing. The field list can be specified in the model.} 14 | s.licenses = ["MIT"] 15 | 16 | s.rubyforge_project = "inline_forms" 17 | 18 | s.files = `git ls-files`.split("\n") 19 | s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") 20 | s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } 21 | s.require_paths = ["lib"] 22 | 23 | s.add_dependency('rvm') 24 | s.add_dependency('thor') 25 | s.add_dependency('validation_hints') 26 | s.add_dependency('rails', '6.1.3.1') 27 | s.add_dependency('rails-i18n') 28 | 29 | end 30 | -------------------------------------------------------------------------------- /lib/generators/USAGE: -------------------------------------------------------------------------------- 1 | Description: 2 | The first argument must be a Model. Next comes a list of name:form_element pairs that describe the model and it's database. 3 | We will generate a model, a migration, a controller and a route. Please do check the migration and the model because they will likely need tweaking. 4 | 5 | Example: 6 | rails generate inline_forms Thing name:text_field description:text_area yesno:check_box gender:boolean_with_values 7 | 8 | This will create: 9 | create app/models/thing.rb 10 | create app/controllers/things_controller.rb 11 | route resources :things 12 | create db/migrate/20110204074707_inline_forms_create_things.rb 13 | 14 | app/models/thing.rb: 15 | class Thing < ApplicationRecord 16 | def _presentation 17 | #define your presentation here 18 | end 19 | def inline_forms_field_list 20 | [ 21 | [ :name, 'name', :text_field ], 22 | [ :description, 'description', :text_area ], 23 | [ :yesno, 'yesno', :check_box ], 24 | [ :gender, 'gender', :boolean_with_values ], 25 | ] 26 | end 27 | end 28 | 29 | app/controllers/things_controller.rb 30 | class ThingsController < InlineFormsController 31 | end 32 | 33 | config/routes.rb: 34 | ... 35 | resources :things 36 | ... 37 | 38 | db/migrate/20111015234500_inline_forms_create_things.rb 39 | class InlineFormsCreateThings < ActiveRecord::Migration 40 | def self.up 41 | create_table :things do |t| 42 | t.string :name 43 | t.text :description 44 | t.boolean :yesno 45 | t.boolean :gender 46 | t.timestamps 47 | end 48 | end 49 | 50 | def self.down 51 | drop_table :things 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /lib/generators/assets/javascripts/ckeditor/config.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. 3 | For licensing, see LICENSE.html or http://ckeditor.com/license 4 | */ 5 | 6 | CKEDITOR.editorConfig = function( config ) 7 | { 8 | // Define changes to default configuration here. For example: 9 | // config.language = 'fr'; 10 | // config.uiColor = '#AADC6E'; 11 | 12 | /* Filebrowser routes */ 13 | // The location of an external file browser, that should be launched when "Browse Server" button is pressed. 14 | config.filebrowserBrowseUrl = "/ckeditor/attachment_files"; 15 | 16 | // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog. 17 | config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files"; 18 | 19 | // The location of a script that handles file uploads in the Flash dialog. 20 | config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files"; 21 | 22 | // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog. 23 | config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures"; 24 | 25 | // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog. 26 | config.filebrowserImageBrowseUrl = "/ckeditor/pictures"; 27 | 28 | // The location of a script that handles file uploads in the Image dialog. 29 | var token = $('meta[name=csrf-token]').attr('content'); 30 | var param = $('meta[name=csrf-param]').attr('content'); 31 | config.filebrowserImageUploadUrl = "/ckeditor/pictures" + "?" + token + "=" + param; 32 | // The location of a script that handles file uploads. 33 | config.filebrowserUploadUrl = "/ckeditor/attachment_files"; 34 | 35 | // Rails CSRF token 36 | config.filebrowserParams = function(){ 37 | var csrf_token = $('meta[name=csrf-token]').attr('content'), 38 | csrf_param = $('meta[name=csrf-param]').attr('content'), 39 | params = new Object(); 40 | 41 | if (csrf_param !== undefined && csrf_token !== undefined) { 42 | params[csrf_param] = csrf_token; 43 | } 44 | 45 | return params; 46 | }; 47 | 48 | config.height = 400; 49 | config.width = 600; 50 | 51 | config.language = 'nl'; 52 | 53 | // these two lines needed for spellchecking in the browser! 54 | config.disableNativeSpellChecker = false; 55 | config.removePlugins = 'contextmenu,liststyle,tabletools'; 56 | 57 | /* Toolbars */ 58 | 59 | config.toolbarCanCollapse = false; 60 | 61 | config.toolbar_Minimal = 62 | [ 63 | ['Format','-','Bold','Italic','Underline','-','NumberedList','BulletedList','-','Link'], 64 | ['PasteFromWord','RemoveFormat','Source','-','Undo','Redo','-','Maximize'] 65 | ]; 66 | 67 | config.toolbar_None = 68 | [ '-' ]; 69 | 70 | config.toolbar = 'Minimal'; 71 | 72 | }; 73 | -------------------------------------------------------------------------------- /lib/generators/assets/stylesheets/inline_forms.scss: -------------------------------------------------------------------------------- 1 | // inline_forms 2 | @import url(http://fonts.googleapis.com/css?family=Open+Sans:400,400italic); 3 | @import 'foundation-icons'; 4 | @import 'themes/jquery.ui.sunny'; 5 | @import 'jquery.ui.all'; 6 | @import 'foundation_and_overrides'; 7 | 8 | .contain-to-grid { 9 | background-color: $body-bg !important; 10 | } 11 | 12 | input { 13 | margin: 2px 0 !important; 14 | } 15 | 16 | select { 17 | background-color: #fff8e0 !important; 18 | border: 0 !important; 19 | margin: 2px 0 !important; 20 | padding: 0; 21 | 22 | } 23 | select:hover, select:focus { 24 | background-color: lighten(#fff8e0, 2%) !important; 25 | border: 0 !important; 26 | } 27 | 28 | #inline_forms_application_top_bar { 29 | background-color: #A3381E; 30 | color: #FFFFFF; 31 | .top-bar-section li a { 32 | background-color: #A3381E; 33 | } 34 | } 35 | 36 | #inline_forms_model_top_bar { 37 | background-color: #E1C150; 38 | padding-top: 45px; 39 | height: 90px; 40 | .top-bar-section { 41 | .right, li, .has-form { 42 | background-color: #E1C150; 43 | } 44 | .inline_forms_model_top_bar_buttons { 45 | top: 4px !important; 46 | padding: 7px 0 7px 0 !important; 47 | margin: 0 !important; 48 | } 49 | .new_button { 50 | background-color: #E1C150; 51 | color: #B94C32; 52 | font-size: 1.3rem; 53 | padding: 0 2rem 0 1rem; 54 | } 55 | .new_button:hover, .new_button:focus { 56 | color: white; 57 | -webkit-transition-property: color; 58 | transition-property: color; 59 | } 60 | input[type=text]:hover, input[type=text]:focus { 61 | background-color: lighten(#fff8e0, 5%); 62 | -webkit-transition-property: background-color; 63 | transition-property: background-color; 64 | } 65 | } 66 | } 67 | 68 | #inline_forms_model_top_bar_container { 69 | z-index: 9; 70 | } 71 | 72 | #outer_container { 73 | width: 100%; 74 | position: absolute; 75 | top: 90px; 76 | } 77 | 78 | .top-level a { 79 | font-weight: bold; 80 | font-size: 110%; 81 | } 82 | .list_container { 83 | .row { 84 | font-size: 1.2rem; 85 | font-weight: normal; 86 | line-height: 2.2rem; 87 | margin: 0 auto !important; 88 | } 89 | .odd { 90 | background-color: #FBE38E; 91 | } 92 | .even { 93 | background-color: #FBEEC1; 94 | } 95 | } 96 | 97 | .inline_forms_list, .new_record { 98 | .row.odd, .row.even { 99 | font-size: 1rem !important; 100 | font-weight: normal !important; 101 | } 102 | .row.form_element_header { 103 | border-top: 1px solid #B94C32; 104 | background-color: rgb(239, 202, 75); 105 | font-weight: normal !important; 106 | font-size: 1.3rem !important; 107 | } 108 | } 109 | 110 | .new_record { 111 | .button { 112 | margin: 0; 113 | padding: 0.5rem; 114 | } 115 | } 116 | 117 | .object_presentation { 118 | background-color: #B94C32; 119 | color: white; 120 | .close_button { 121 | background-color: #B94C32; 122 | font-size: 1.3rem; 123 | padding: 0 1rem 0 1rem; 124 | margin: 0; 125 | } 126 | .close_button:hover, .close_button:focus { 127 | background-color: #B94C32; 128 | color: #FBEEC1; 129 | -webkit-transition-property: color; 130 | transition-property: color; 131 | } 132 | } 133 | 134 | .list_container { 135 | .row.odd, .row.even { 136 | font-size: 1rem !important; 137 | font-weight: normal !important; 138 | } 139 | .row.form_element_header { 140 | border-top: 1px solid #B94C32; 141 | background-color: rgb(239, 202, 75); 142 | font-weight: normal !important; 143 | font-size: 1.3rem !important; 144 | } 145 | } 146 | 147 | 148 | 149 | .associated_auto_header { 150 | border-top: 1px solid #B94C32; 151 | .new_button { 152 | background-color: rgb(239, 202, 75); 153 | font-size: 1.5rem; 154 | color: #B94C32; 155 | padding: 0 0.5rem 0 1rem; 156 | margin: 0; 157 | } 158 | .new_button:hover, .new_button:focus { 159 | background-color: rgb(239, 202, 75); 160 | color: white; 161 | -webkit-transition-property: color; 162 | transition-property: color; 163 | } 164 | .close_button { 165 | background-color: rgb(239, 202, 75); 166 | font-size: 1.5rem; 167 | color: #B94C32; 168 | padding: 0 0.5rem 0 1rem; 169 | margin: 0; 170 | } 171 | .close_button:hover, .new_button:focus { 172 | background-color: rgb(239, 202, 75); 173 | color: white; 174 | -webkit-transition-property: color; 175 | transition-property: color; 176 | } 177 | } 178 | 179 | .pagination { 180 | font-weight: normal; 181 | font-size: 0.9em; 182 | a:hover { 183 | color: #B94C32; 184 | -webkit-transition-property: color; 185 | -webkit-transition-duration: 0.3s; 186 | transition-property: color; 187 | transition-duration: 0.3s; 188 | } 189 | em { 190 | color: #B94C32; 191 | font-weight: bold; 192 | font-style: normal; 193 | } 194 | span.disabled { 195 | color: #AAA; 196 | } 197 | } 198 | 199 | .record_footer { 200 | background-color: rgb(239, 202, 75); 201 | height: 0.2em; 202 | border-bottom: 1px solid #B94C32; 203 | margin-bottom: 1.5em; 204 | } 205 | 206 | .flash { 207 | margin-top: 1em; 208 | padding: 0.5em; 209 | color: #A3381E; 210 | font-size: 130%; 211 | font-weight: bold; 212 | line-height: 120%; 213 | background-color: white; 214 | border-top: 0.5em solid #fade7a; 215 | } 216 | 217 | .custom-combobox { 218 | position: relative; 219 | display: inline-block; 220 | } 221 | .custom-combobox-toggle { 222 | position: absolute; 223 | top: 0; 224 | bottom: 0; 225 | margin-left: -1px; 226 | padding: 0; 227 | /* support: IE7 */ 228 | *height: 1.7em; 229 | *top: 0.1em; 230 | } 231 | .custom-combobox-input { 232 | margin: 0; 233 | padding: 0.3em; 234 | } 235 | 236 | 237 | .column { 238 | padding-right: 0 !important; 239 | } 240 | 241 | .top-bar input, .top-bar .button { 242 | top: 4px !important; 243 | } 244 | 245 | .top-bar-section { 246 | padding-left: rem-calc(12) !important; 247 | padding-right: rem-calc(12) !important; 248 | } 249 | 250 | .first-bar { 251 | margin-bottom: 0 !important; 252 | } 253 | .second-bar { 254 | margin-top: 1px !important; 255 | margin-bottom: 0 !important; 256 | } 257 | 258 | #switch_user_identifier { 259 | font-size: smaller; 260 | select { 261 | width: 5em; 262 | } 263 | } 264 | 265 | 266 | .error { 267 | color: #ffffff; 268 | font-weight: bold; 269 | -moz-border-radius: 10px; 270 | -webkit-border-radius: 10px; 271 | -webkit-box-shadow: 0 1px 1px rgba(0,0,0, .1); 272 | -moz-box-shadow: 0 1px 1px rgba(0,0,0, .1); 273 | background-color: #a70f0f; 274 | background-image: -moz-linear-gradient(100% 100% 90deg, #a70f0f, #c01313); 275 | background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#c01313), to(#a70f0f)); 276 | padding: 0.7em; 277 | } 278 | .success { 279 | color: #ffffff; 280 | font-weight: bold; 281 | -moz-border-radius: 5px; 282 | -webkit-border-radius: 5px; 283 | -webkit-box-shadow: 0 1px 3px rgba(0,0,0, .4); 284 | -moz-box-shadow: 0 1px 3px rgba(0,0,0, .4); 285 | border-bottom: 1px solid #cccccc; 286 | background-color: #4f8d0d; 287 | background-image: -moz-linear-gradient(100% 100% 90deg, #4f8d0d, #5ba210); 288 | background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#5ba210), to(#4f8d0d)); 289 | padding: 0.7em; 290 | margin-bottom: 0.5em; 291 | } 292 | 293 | .ckeditor_area { 294 | position: relative; 295 | } 296 | 297 | .ckeditor_area .glass_plate { 298 | position: absolute; 299 | top: -1px; 300 | width: 98%; 301 | height: 232px; 302 | border: 0; 303 | } 304 | 305 | .ckeditor_area .cke_top, .ckeditor_area .cke_bottom, .ckeditor_area .cke_border { 306 | display: none; 307 | } 308 | 309 | /* jQuery ui Slider 8 */ 310 | .slider { 311 | width: 300px; 312 | float: left; 313 | } 314 | .slider_value { 315 | float: left; 316 | min-width: 60px; 317 | text-align: right; 318 | font-family: monospace; 319 | } 320 | 321 | 322 | /* LEFT */ 323 | 324 | #category_id { 325 | margin-top: -2px !important; 326 | } 327 | 328 | #input_search { 329 | border: none !important; 330 | margin-top: -2px; 331 | } 332 | 333 | #inline_forms_model_top_bar .top-bar-section .inline_forms_model_top_bar_buttons { 334 | top: 6px !important; 335 | } 336 | -------------------------------------------------------------------------------- /lib/generators/assets/stylesheets/inline_forms_devise.css: -------------------------------------------------------------------------------- 1 | /* Put here your custom styles for inline_forms devise views */ 2 | -------------------------------------------------------------------------------- /lib/generators/inline_forms_generator.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | require File.expand_path(File.join(File.dirname(__FILE__),'../../app/helpers/inline_forms_helper.rb')) 3 | module InlineForms 4 | # == Usage 5 | # This generator generates a migration, a model and a controller. 6 | # 7 | # rails g inline_forms Model attribute:type [attribute:type ...] [options] 8 | # 9 | # Read more about the possible types below. 10 | # 11 | # == Overriding Rails::Generators::GeneratedAttribute 12 | # When using a generator in the form 13 | # rails g example_generator Modelname attribute:type attribute:type ... 14 | # an array with attributes and types is created for use in the generator. 15 | # 16 | # Rails::Generators::GeneratedAttribute creates, among others, a attribute_type. 17 | # This attribute_type maps column types to form attribute helpers like text_field. 18 | # We override it here to make our own. 19 | # 20 | class InlineFormsGenerator < Rails::Generators::NamedBase 21 | Rails::Generators::GeneratedAttribute.class_eval do #:doc: 22 | # Deducts the column_type for migrations from the type. 23 | # 24 | # We first merge the Special Column Types with the Default Column Types, 25 | # which has the effect that the Default Column Types with the same key override 26 | # the Special Column Types. 27 | # 28 | # If the type is not in the merged hash, then column_type defaults to :unknown 29 | # 30 | # You are advised to check you migrations for the :unknown, because either you made a 31 | # typo in the generator command line or you need to add a Form Element! 32 | # 33 | def column_type 34 | SPECIAL_COLUMN_TYPES.merge(DEFAULT_COLUMN_TYPES).merge(RELATIONS).merge(SPECIAL_RELATIONS)[type] || :unknown 35 | end 36 | 37 | # Override the attribute_type to include our special column types. 38 | # 39 | # If a type is not in the Special Column Type hash, then the default 40 | # column type hash is used, and if that fails, the attribute_type 41 | # will be :unknown. Make sure to check your models for the :unknown. 42 | # 43 | def attribute_type 44 | SPECIAL_COLUMN_TYPES.merge(RELATIONS).has_key?(type) ? type : DEFAULT_FORM_ELEMENTS[type] || :unknown 45 | end 46 | 47 | def special_relation? 48 | SPECIAL_RELATIONS.has_key?(type) 49 | end 50 | 51 | def relation? 52 | RELATIONS.has_key?(type) || special_relation? 53 | end 54 | 55 | def migration? 56 | not ( column_type == :no_migration || 57 | name == "_presentation" || 58 | name == "_order" || 59 | name == "_enabled" || 60 | name == "_id" ) 61 | end 62 | 63 | def attribute? 64 | not ( name == '_presentation' || 65 | name == '_order' || 66 | name == '_enabled' || 67 | name == "_id" || 68 | relation? ) 69 | end 70 | 71 | 72 | end 73 | argument :attributes, :type => :array, :banner => "[name:form_element]..." 74 | 75 | source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates')) 76 | 77 | # using flags. 78 | def set_some_flags 79 | @flag_not_accessible_through_html = true 80 | @flag_create_migration = true 81 | @flag_create_model = true 82 | @create_id = true 83 | for attribute in attributes 84 | @flag_not_accessible_through_html = false if attribute.name == '_enabled' 85 | @flag_create_migration = false if attribute.name == '_no_migration' 86 | @flag_create_model = false if attribute.name == '_no_model' 87 | @create_id = false if attribute.name == "_id" && attribute.type == :false 88 | end 89 | @flag_create_controller = @flag_create_model 90 | @flag_create_resource_route = @flag_create_model 91 | end 92 | 93 | def generate_model 94 | if @flag_create_model 95 | @belongs_to = "\n" 96 | @has_many = "\n" 97 | @has_one = "\n" 98 | @habtm = "\n" 99 | @has_attached_files = "\n" 100 | @presentation = "\n" 101 | @order = "\n" 102 | @order_by_clause = " def self.order_by_clause\n" + 103 | " \"name\"\n" + 104 | " end\n" + 105 | "\n" 106 | @carrierwave_mounters = "\n" 107 | @inline_forms_attribute_list = String.new 108 | 109 | for attribute in attributes 110 | if attribute.column_type == :belongs_to 111 | ## :drop_down, :references and :belongs_to all end up with the column_type :belongs_to 112 | @belongs_to << ' belongs_to :' + attribute.name + "\n" 113 | end 114 | # upload images or audio files via carrierwave 115 | case attribute.type when :image_field, :audio_field then 116 | @carrierwave_mounters << ' mount_uploader :' + attribute.name + ', ' + "#{attribute.name}_uploader".camelcase + "\n" 117 | end 118 | if attribute.type == :has_many || 119 | attribute.type == :has_many_destroy 120 | @has_many << ' has_many :' + attribute.name 121 | @has_many << ', :dependent => :destroy' if attribute.type == :has_many_destroy 122 | @has_many << "\n" 123 | end 124 | if attribute.type == :has_one 125 | @has_one << ' has_one :' + attribute.name + "\n" 126 | end 127 | if attribute.type == :habtm || 128 | attribute.type == :has_and_belongs_to_many || 129 | attribute.type == :check_list 130 | @habtm << ' has_and_belongs_to_many :' + attribute.name + "\n" 131 | end 132 | if attribute.name == '_presentation' 133 | @presentation << " def _presentation\n" + 134 | " \"#{attribute.type.to_s}\"\n" + 135 | " end\n" + 136 | "\n" 137 | end 138 | if attribute.name == '_order' 139 | @order << " def <=>(other)\n" + 140 | " self.#{attribute.type} <=> other.#{attribute.type}\n" + 141 | " end\n" + 142 | "\n" 143 | @order_by_clause = " def self.order_by_clause\n" + 144 | " \"#{attribute.type}\"\n" + 145 | " end\n" + 146 | "\n" 147 | end 148 | if attribute.attribute? 149 | attribute.attribute_type == :unknown ? commenter = '#' : commenter = ' ' 150 | @inline_forms_attribute_list << commenter + 151 | ' [ :' + 152 | attribute.name + 153 | ' , "' + attribute.name + 154 | '", :' + attribute.attribute_type.to_s + 155 | " ], \n" 156 | end 157 | end 158 | unless @inline_forms_attribute_list.empty? 159 | @inline_forms_attribute_list = "\n" + 160 | " def inline_forms_attribute_list\n" + 161 | " @inline_forms_attribute_list ||= [\n" + 162 | @inline_forms_attribute_list + 163 | " ]\n" + 164 | " end\n" + 165 | "\n" 166 | end 167 | template "model.erb", "app/models/#{model_file_name}.rb" 168 | end 169 | end 170 | 171 | def generate_resource_route 172 | if @flag_create_resource_route 173 | route <<-ROUTE.strip_heredoc 174 | resources :#{resource_name} do 175 | post 'revert', :on => :member 176 | get 'list_versions', :on => :member 177 | end 178 | ROUTE 179 | end 180 | end 181 | 182 | def generate_migration 183 | if @flag_create_migration 184 | @columns = String.new 185 | 186 | for attribute in attributes 187 | if attribute.column_type == :image 188 | @columns << ' t.string :' + attribute.name + "_file_name\n" 189 | @columns << ' t.string :' + attribute.name + "_content_type\n" 190 | @columns << ' t.integer :' + attribute.name + "_file_size\n" 191 | @columns << ' t.datetime :' + attribute.name + "_updated_at\n" 192 | else 193 | if attribute.migration? 194 | attribute.attribute_type == :unknown ? commenter = '#' : commenter = ' ' 195 | @columns << commenter + 196 | ' t.' + 197 | attribute.column_type.to_s + 198 | " :" + 199 | attribute.name + 200 | " \n" 201 | end 202 | end 203 | end 204 | @primary_key_option = @create_id ? '' : ', id: false' 205 | template "migration.erb", "db/migrate/#{time_stamp}_inline_forms_create_#{table_name}.rb" 206 | end 207 | end 208 | 209 | def add_second_top_bar 210 | copy_file "_inline_forms_tabs.html.erb", "app/views/_inline_forms_tabs.html.erb" unless File.exist?('app/views/_inline_forms_tabs.html.erb') 211 | end 212 | 213 | def add_tab 214 | unless @flag_not_accessible_through_html 215 | inject_into_file "app/controllers/application_controller.rb", 216 | "#{name.pluralize.underscore} ", 217 | :after => "ActionView::CompiledTemplates::MODEL_TABS = %w(" 218 | end 219 | end 220 | 221 | def generate_test 222 | template "test.erb", "test/unit/#{test_file_name}.rb" 223 | end 224 | 225 | def generate_controller 226 | template "controller.erb", "app/controllers/#{controller_file_name}.rb" if @flag_create_controller 227 | end 228 | 229 | 230 | private 231 | def model_file_name 232 | name.underscore 233 | end 234 | 235 | def resource_name 236 | name.pluralize.underscore 237 | end 238 | 239 | def controller_name 240 | name.pluralize + 'Controller' 241 | end 242 | 243 | def controller_file_name 244 | controller_name.underscore 245 | end 246 | 247 | def test_name 248 | name + 'Test' 249 | end 250 | 251 | def test_file_name 252 | test_name.underscore 253 | end 254 | 255 | def table_name 256 | name.pluralize.underscore 257 | end 258 | 259 | def time_stamp 260 | Time.now.utc.strftime("%Y%m%d%H%M%S") 261 | # found it here http://whynotwiki.com/Ruby_/_Dates_and_times 262 | end 263 | 264 | end 265 | end 266 | -------------------------------------------------------------------------------- /lib/generators/templates/_inline_forms_tabs.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 41 |
-------------------------------------------------------------------------------- /lib/generators/templates/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | 4 | # Wrapper for @model.human_attribute_name -> Model.human_attribute_name 5 | def human_attribute_name(*args) 6 | self.class.human_attribute_name(*args) 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /lib/generators/templates/capistrano/Capfile: -------------------------------------------------------------------------------- 1 | # Load DSL and set up stages 2 | require "capistrano/setup" 3 | 4 | # Include default deployment tasks 5 | require "capistrano/deploy" 6 | 7 | # Load the SCM plugin appropriate to your project: 8 | # 9 | # require "capistrano/scm/hg" 10 | # install_plugin Capistrano::SCM::Hg 11 | # or 12 | # require "capistrano/scm/svn" 13 | # install_plugin Capistrano::SCM::Svn 14 | # or 15 | require "capistrano/scm/git" 16 | install_plugin Capistrano::SCM::Git 17 | 18 | # Include tasks from other gems included in your Gemfile 19 | # 20 | # For documentation on these, see for example: 21 | # 22 | # https://github.com/capistrano/rvm 23 | # https://github.com/capistrano/rbenv 24 | # https://github.com/capistrano/chruby 25 | # https://github.com/capistrano/bundler 26 | # https://github.com/capistrano/rails 27 | # https://github.com/capistrano/passenger 28 | # 29 | require 'rvm1/capistrano3' 30 | # require "capistrano/rbenv" 31 | # require "capistrano/chruby" 32 | require "capistrano/bundler" 33 | require "capistrano/rails/assets" 34 | require "capistrano/rails/migrations" 35 | # require "capistrano/passenger" 36 | require "capistrano3/unicorn" 37 | 38 | # Load custom tasks from `lib/capistrano/tasks` if you have any defined 39 | Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } 40 | -------------------------------------------------------------------------------- /lib/generators/templates/capistrano/deploy.rb: -------------------------------------------------------------------------------- 1 | set :application, ENV['DEPLOY_APPLICATION'] 2 | set :repo_url, ENV['DEPLOY_REPO_URL'] 3 | set :bundle_binstubs, nil 4 | 5 | # Default deploy_to directory is /var/www/my_app_name 6 | set :deploy_to, ENV['DEPLOY_DIRECTORY'] 7 | 8 | # Default value for :linked_files is [] 9 | set :linked_files, fetch(:linked_files, []) 10 | .push("config/application.yml") 11 | # Default value for linked_dirs is [] 12 | set :linked_dirs, fetch(:linked_dirs, []) 13 | .push("log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system", "vendor/bundle") 14 | 15 | # Default value for keep_releases is 5 16 | set :keep_releases, 5 17 | 18 | before 'rvm1:install:rvm', 'app:update_rvm_key' 19 | after 'rvm1:install:ruby', 'rvm1:install_bundler' 20 | 21 | before 'deploy', 'rvm1:install:rvm' # install/update RVM 22 | before 'deploy', 'rvm1:install:ruby' # install/update Ruby 23 | 24 | before 'deploy:check', 'figaro:upload' 25 | after 'deploy:publishing', 'deploy:restart' 26 | 27 | # Restart unicorn 28 | namespace :deploy do 29 | task :restart do 30 | invoke "unicorn:restart" 31 | end 32 | end 33 | 34 | # Uploads secrets.yml, database.yml and application.yml files 35 | namespace :figaro do 36 | task :upload do 37 | on roles(:all) do 38 | execute "mkdir -p #{shared_path}/config" 39 | upload! 'config/application.yml', "#{shared_path}/config/application.yml" 40 | end 41 | end 42 | end 43 | 44 | namespace :app do 45 | task :update_rvm_key do 46 | roles(:all) do 47 | execute :gpg, "--keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3" 48 | end 49 | end 50 | end 51 | 52 | namespace :rvm1 do # https://github.com/rvm/rvm1-capistrano3/issues/45 53 | desc "Install Bundler" 54 | task :install_bundler do 55 | on release_roles :all do 56 | execute "cd #{release_path} && #{fetch(:rvm1_auto_script_path)}/rvm-auto.sh . gem install bundler" 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /lib/generators/templates/capistrano/production.rb: -------------------------------------------------------------------------------- 1 | set :user, ENV["DEPLOY_USER"] 2 | set :deploy_via, :remote_cache 3 | set :conditionally_migrate, true 4 | set :rails_env, "production" 5 | 6 | # Server IP 7 | server ENV["DEPLOY_HOST"], user: fetch(:user), port: fetch(:port), roles: %w(web app db) 8 | -------------------------------------------------------------------------------- /lib/generators/templates/controller.erb: -------------------------------------------------------------------------------- 1 | class <%= controller_name -%> < InlineFormsController 2 | <%= " set_tab :" + name.underscore + "\n" unless @flag_not_accessible_through_html -%> 3 | end 4 | -------------------------------------------------------------------------------- /lib/generators/templates/migration.erb: -------------------------------------------------------------------------------- 1 | class InlineFormsCreate<%= table_name.camelize %> < ActiveRecord::Migration[6.1] 2 | 3 | def self.up 4 | create_table :<%= table_name + @primary_key_option %> do |t| 5 | <%= @columns -%> 6 | t.timestamps 7 | end 8 | end 9 | 10 | def self.down 11 | drop_table :<%= table_name %> 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /lib/generators/templates/model.erb: -------------------------------------------------------------------------------- 1 | class <%= name %> < ApplicationRecord 2 | attr_reader :per_page 3 | @per_page = 7 4 | attr_writer :inline_forms_attribute_list 5 | has_paper_trail 6 | <%= @carrierwave_mounters if @carrierwave_mounters.length > 1 -%> 7 | <%= @belongs_to if @belongs_to.length > 1 -%> 8 | <%= @has_many if @has_many.length > 1 -%> 9 | <%= @has_one if @has_one.length > 1 -%> 10 | <%= @habtm if @habtm.length > 1 -%> 11 | <%= @has_attached_files if @has_attached_files.length > 1 -%> 12 | <%= @presentation if @presentation.length > 1 -%> 13 | <%= @inline_forms_attribute_list -%> 14 | <%= @order if @order.length > 1 -%> 15 | 16 | def self.not_accessible_through_html? 17 | <%= @flag_not_accessible_through_html %> 18 | end 19 | 20 | <%= @order_by_clause -%> 21 | 22 | end 23 | -------------------------------------------------------------------------------- /lib/generators/templates/test.erb: -------------------------------------------------------------------------------- 1 | class <%= test_name %> < ActiveSupport::TestCase 2 | # Replace this with your real tests. 3 | test "the truth" do 4 | assert true 5 | end 6 | end -------------------------------------------------------------------------------- /lib/generators/templates/unicorn/production.rb: -------------------------------------------------------------------------------- 1 | # Load ENV vars via Figaro 2 | require 'figaro' 3 | Figaro.application = Figaro::Application.new(environment: 'production', path: File.expand_path('../../../config/application.yml', __FILE__)) 4 | Figaro.load 5 | 6 | app_path = "#{ENV['DEPLOY_DIRECTORY']}/current" 7 | working_directory app_path 8 | 9 | pid "#{app_path}/tmp/pids/unicorn.pid" 10 | 11 | stderr_path "#{app_path}/log/unicorn.err.log" 12 | stdout_path "#{app_path}/log/unicorn.out.log" 13 | 14 | worker_processes 3 15 | timeout 30 16 | preload_app true 17 | 18 | listen "#{app_path}/tmp/sockets/unicorn.sock", backlog: 64 19 | 20 | before_exec do |_| 21 | ENV["BUNDLE_GEMFILE"] = File.join(app_path, "Gemfile") 22 | end 23 | 24 | before_fork do |server, worker| 25 | defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! 26 | 27 | old_pid = "#{app_path}/tmp/pids/unicorn.pid.oldbin" 28 | 29 | if File.exist?(old_pid) && server.pid != old_pid 30 | begin 31 | Process.kill("QUIT", File.read(old_pid).to_i) 32 | rescue Errno::ENOENT, Errno::ESRCH 33 | end 34 | end 35 | end 36 | 37 | after_fork do |server, worker| 38 | defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection 39 | end 40 | -------------------------------------------------------------------------------- /lib/inline_forms.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | require ('inline_forms/version.rb') 3 | # InlineForms is a Rails Engine that let you setup an admin interface quick and 4 | # easy. Please install it as a gem or include it in your Gemfile. 5 | module InlineForms 6 | # DEFAULT_COLUMN_TYPES holds the standard ActiveRecord::Migration column types. 7 | # This list provides compatability with the standard types, but we add our own 8 | # later in 'Special Column Types'. 9 | # 10 | # These types will override Special Column Types of the same name.\ 11 | # 12 | # Example: 13 | # rails g inline_forms Example name:string price:integer 14 | # will result in: 15 | # class InlineFormsCreateExamples < ActiveRecord::Migration 16 | # def self.up 17 | # create_table :examples do |t| 18 | # t.string :name 19 | # t.integer :price 20 | # t.timestamps 21 | # end 22 | # end 23 | # def self.down 24 | # drop_table :examples 25 | # end 26 | # end 27 | # 28 | DEFAULT_COLUMN_TYPES = { 29 | :string => :string, 30 | :text => :text, 31 | :integer => :integer, 32 | :float => :float, 33 | :decimal => :decimal, 34 | :datetime => :datetime, 35 | :timestamp => :timestamp, 36 | :time => :time, 37 | :date => :date, 38 | :binary => :binary, 39 | :boolean => :boolean, 40 | # :references => :belongs_to, 41 | # :belongs_to => :belongs_to, 42 | } 43 | 44 | # DEFAULT_FORM_ELEMENTS holds a mapping from Default Column Types to 45 | # Form Elements. Form Elements are defined in lib/app/helpers/form_elements 46 | # and are pieces of code that display a form for a field. 47 | # 48 | # Example: 49 | # rails g inline_forms Example name:string price:integer 50 | # will result in the following model: 51 | # 52 | # class Example < ApplicationRecord 53 | # def inline_forms_attribute_list 54 | # { 55 | # :name => [ "name", :text_field ], 56 | # :price => [ "price", :text_field ], 57 | # } 58 | # end 59 | # end 60 | # as you see, both :string and :integer are mapped to a :text_field 61 | # 62 | DEFAULT_FORM_ELEMENTS = { 63 | :string => :text_field, 64 | :text => :text_area, 65 | :integer => :text_field, 66 | :float => :text_field, 67 | :decimal => :text_field, 68 | :datetime => :datetime_select, 69 | :timestamp => :datetime_select, 70 | :time => :time_select, 71 | :date => :date_select, 72 | :binary => :text_field, 73 | :boolean => :check_box, 74 | } 75 | 76 | # SPECIAL_COLUMN_TYPES maps the column types that we define here and in 77 | # lib/app/helpers/form_elements to the standard ActiveRecord::Migration column 78 | # types 79 | # 80 | # Example: in lib/app/helpers/form_elements/dropdown.rb 81 | # InlineForms::SPECIAL_COLUMN_TYPES[:dropdown]=:belongs_to 82 | # this maps the :dropdown form element to the :belongs_to column type. 83 | # 84 | # If you call the generator with country:dropdown, it will add 85 | # t.belongs_to :country 86 | # to the migration. (In fact AR will add t.integer :country_id). And 87 | # it will add 88 | # :country => [ "country", :dropdown ], 89 | # to the inline_forms_attribute_list in the model. 90 | # 91 | SPECIAL_COLUMN_TYPES = { 92 | :associated => :no_migration 93 | } 94 | 95 | # RELATIONS defines a mapping between AR::Migrations columns and the Model. 96 | # 97 | # When a column has the type of :references or :belongs_to, then 98 | # there will be a line in the migration reflecting that, but not in the model. 99 | # == Why? 100 | # * Let's say we have a customer that has_many phone_numbers. 101 | # * Let's say that a phone_number belongs_to a customer. 102 | # * Let's say that every number has_one type_of_number (like 'private','gsm' etc.) 103 | # * Let's say a type_of_number belongs_to a number. 104 | # 105 | # Wait a minute... thats sounds right... but it ain't! 106 | # 107 | # In fact, a type_of_number has_many phone_numbers and a phone_number belongs_to a type_of_number! 108 | # 109 | # In a form, it's quite logical to use a dropdown for type_of_number. So, in the generator, use 110 | # type_of_number:dropdown 111 | # This creates the correct migration (t.integer :type_of_number_id) and the correct model. 112 | # (It adds 'belongs_to :type_of_number' and adds a dropdown in the inline_forms_attribute_list) 113 | # 114 | # But, you also want to have a client_id in the migration, and a 'belongs_to :client' in the model. 115 | # In such cases, you need to use :belongs_to, like this: 116 | # rails g inline_forms Example phone_number:string type_of_number:dropdown client:belongs_to 117 | # 118 | RELATIONS = { 119 | :belongs_to => :belongs_to, 120 | :references => :belongs_to, 121 | } 122 | 123 | # SPECIAL_RELATIONS maps AR relations to migrations. 124 | # In most cases, these relations have no migration at all, but they do need 125 | # a line in the model. 126 | SPECIAL_RELATIONS = { 127 | :has_many => :no_migration, 128 | :has_many_destroy => :no_migration, 129 | :has_one => :no_migration, 130 | :has_and_belongs_to_many => :no_migration, 131 | :habtm => :no_migration, 132 | } 133 | 134 | # load form elements. Each element goes into a separate file 135 | # and defines a _show, _edit and _update method. 136 | # 137 | 138 | # Declare as a Rails::Engine, see http://www.ruby-forum.com/topic/211017#927932 139 | class Engine < Rails::Engine 140 | 141 | initializer "inline_forms.assets.precompile" do |app| 142 | app.config.assets.precompile += %w( 143 | inline_forms/inline_forms.css 144 | inline_forms/devise.css 145 | inline_forms/inline_forms.js 146 | inline_forms/ckeditor/config.js 147 | inline_forms/glass_plate.gif 148 | ) 149 | end 150 | 151 | I18n.load_path << Dir[File.join(File.expand_path(File.dirname(__FILE__) + '/locales'), '*.yml')] 152 | I18n.load_path.flatten! 153 | end 154 | 155 | end 156 | 157 | # make the current method and the calling method available 158 | # http://www.ruby-forum.com/topic/75258 159 | # supposedly, this is fixed in 1.9 160 | module Kernel 161 | private 162 | def this_method 163 | caller[0] =~ /`([^']*)'/ and $1 164 | end 165 | def calling_method 166 | caller[1] =~ /`([^']*)'/ and $1 167 | end 168 | end 169 | -------------------------------------------------------------------------------- /lib/inline_forms/version.rb: -------------------------------------------------------------------------------- 1 | # -*- encoding : utf-8 -*- 2 | module InlineForms 3 | VERSION = "6.2.14" 4 | end 5 | -------------------------------------------------------------------------------- /lib/locales/inline_forms.en.yml: -------------------------------------------------------------------------------- 1 | en: 2 | inline_forms: 3 | general: 4 | application_title: Application Title 5 | devise: 6 | title_for_devise: Title for Devise 7 | welcome: Welcome for Devise 8 | passwords: 9 | forgot_your_password: Forgot Your Password? 10 | change_your_password: Change your password, if you want! 11 | send_me_instructions: send instuctions 12 | change_my_password: change password 13 | send_instructions: send instructions 14 | sign_up: sign up 15 | login_with_email_and_password: login with email and password 16 | sign_in: sign in 17 | links: 18 | no_unlock_instructions: did you not receive unlock instructions? 19 | sign_up: sign up 20 | sign_in: sing in 21 | forgot_password: forgot password? 22 | sign_in_with: sign in with %{provider} 23 | no_instructions: did you not receive instructions? 24 | signup_with_email_name_and_password: sign up with email name and password 25 | provide_email_and_we_send_instructions: provide your email and we will send instructions 26 | view: 27 | close: close 28 | add_new: make a new %{model} 29 | undo: undo 30 | restore: restore 31 | trash: trash 32 | list_versions: List versions 33 | close_versions_list: Close versions list 34 | succes: success. 35 | activerecord: 36 | models: 37 | language: language 38 | attributes: 39 | client: 40 | first_name: first name 41 | last_name: last name 42 | -------------------------------------------------------------------------------- /lib/locales/inline_forms.nl.yml: -------------------------------------------------------------------------------- 1 | nl: 2 | inline_forms: 3 | general: 4 | application_title: Application Title 5 | devise: 6 | title_for_devise: Title for Devise 7 | welcome: Welcome for Devise 8 | passwords: 9 | forgot_your_password: Wachtwoord Vergeten? 10 | change_your_password: Verander wachtwoord, als u wilt! 11 | send_me_instructions: stuur instructies 12 | change_my_password: verander wachtwoord 13 | send_instructions: stuur instructies 14 | sign_up: inschrijven 15 | login_with_email_and_password: aanmelden door email-adres en wachtwoord in te voeren. 16 | sign_in: aanmelden 17 | links: 18 | no_unlock_instructions: geen instructies ontvangen om blokkade op te heffen? 19 | sign_up: inschrijven 20 | sign_in: aanmelden 21 | forgot_password: wachtwoord vergeten? 22 | sign_in_with: aanmelden via %{provider} 23 | no_instructions: geen instructies ontvangen? 24 | signup_with_email_name_and_password: inschrijven door naam, email adres en wachtwoord (twee keer) in te voeren. 25 | provide_email_and_we_send_instructions: geef ons uw email adres, dan sturen wij u instructies 26 | view: 27 | close: sluiten 28 | add_new: Maak een nieuw %{model} 29 | undo: terughalen 30 | trash: weggooien 31 | succes: het ding is aangemaakt. 32 | activerecord: 33 | models: 34 | language: taal 35 | attributes: 36 | client: 37 | first_name: voornaam 38 | last_name: achternaam 39 | application_name: naam van de applicatie 40 | 41 | 42 | -------------------------------------------------------------------------------- /lib/otherstuff/20120310065554_inline_forms_create_view_for_translations.rb: -------------------------------------------------------------------------------- 1 | class InlineFormsCreateViewForTranslations < ActiveRecord::Migration 2 | 3 | execute 'CREATE VIEW translations ( locale, thekey, value, interpolations, is_proc ) 4 | AS 5 | SELECT L.name, K.name, T.value, T.interpolations, T.is_proc 6 | FROM if_keys K, if_locales L, if_translations T 7 | WHERE T.if_key_id = K.id AND T.i_locale_id = L.id ' 8 | 9 | end 10 | 11 | def self.down 12 | execute 'DROP VIEW translations' 13 | end 14 | 15 | 16 | end 17 | -------------------------------------------------------------------------------- /lib/otherstuff/add_roles.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.13 Distrib 5.1.49, for debian-linux-gnu (i686) 2 | -- 3 | -- Host: localhost Database: RumboTS_development 4 | -- ------------------------------------------------------ 5 | -- Server version 5.1.49-1ubuntu8.1 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `roles` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `roles`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `roles` ( 26 | `id` int(11) NOT NULL AUTO_INCREMENT, 27 | `name` varchar(255) DEFAULT NULL, 28 | `active` tinyint(1) DEFAULT NULL, 29 | `created_at` datetime DEFAULT NULL, 30 | `updated_at` datetime DEFAULT NULL, 31 | PRIMARY KEY (`id`) 32 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; 33 | /*!40101 SET character_set_client = @saved_cs_client */; 34 | 35 | -- 36 | -- Dumping data for table `roles` 37 | -- 38 | 39 | LOCK TABLES `roles` WRITE; 40 | /*!40000 ALTER TABLE `roles` DISABLE KEYS */; 41 | INSERT INTO `roles` VALUES (1,'admin',1,'2011-05-23 09:47:25','2011-05-23 09:47:25'),(2,'user',1,'2011-05-23 22:47:04','2011-05-23 22:47:04'); 42 | /*!40000 ALTER TABLE `roles` ENABLE KEYS */; 43 | UNLOCK TABLES; 44 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 45 | 46 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 47 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 48 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 49 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 50 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 51 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 52 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 53 | 54 | -- Dump completed on 2011-06-14 4:14:08 55 | -------------------------------------------------------------------------------- /lib/otherstuff/mkiftrans: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rails g inline_forms IFLocale \ 3 | name:string \ 4 | if_translations:belongs_to \ 5 | _enabled:yes _presentation:'#{name}' -f 6 | 7 | rails g inline_forms IFKey \ 8 | name:string \ 9 | if_translations:has_many if_translations:associated \ 10 | _enabled:yes _presentation:'#{name}' -f 11 | 12 | rails g inline_forms IFTranslation \ 13 | if_key:belongs_to \ 14 | if_locale:dropdown \ 15 | value:text \ 16 | interpolations:text \ 17 | is_proc:boolean \ 18 | _presentation:'#{value}' -f 19 | 20 | bundle exec rake db:migrate 21 | 22 | -------------------------------------------------------------------------------- /lib/otherstuff/mkrole: -------------------------------------------------------------------------------- 1 | rails g inline_forms Role \ 2 | name:string \ 3 | active:check_box \ 4 | _enabled:yes \ 5 | _presentation:'#{name}' \ 6 | _order:name -f 7 | 8 | -------------------------------------------------------------------------------- /lib/otherstuff/roles_users.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.13 Distrib 5.1.49, for debian-linux-gnu (i686) 2 | -- 3 | -- Host: localhost Database: RumboTS_development 4 | -- ------------------------------------------------------ 5 | -- Server version 5.1.49-1ubuntu8.1 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `roles_users` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `roles_users`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `roles_users` ( 26 | `role_id` int(11) DEFAULT NULL, 27 | `user_id` int(11) DEFAULT NULL 28 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1; 29 | /*!40101 SET character_set_client = @saved_cs_client */; 30 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 31 | 32 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 33 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 34 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 35 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 36 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 37 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 38 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 39 | 40 | -- Dump completed on 2011-06-14 4:15:21 41 | -------------------------------------------------------------------------------- /lib/vagrant/vagrantbox-inline_forms.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acesuares/inline_forms/9d25349c247f9473a09ccdb2655d17532598b6a5/lib/vagrant/vagrantbox-inline_forms.zip --------------------------------------------------------------------------------