Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

prevent RailsAdmin from loading with environment when a rake task req…

…uests it

fix the build
sorry for the CRLF mess.
  • Loading branch information...
commit 08545c6dcba54009dd76b4af3928a60eb816ece0 1 parent 87e5161
@bbenezech bbenezech authored
View
3,084 README.md
1,545 additions, 1,539 deletions not shown
View
27 Rakefile
@@ -1,13 +1,14 @@
-# Add your own tasks in files placed in lib/tasks ending in .rake,
-# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-
-Dir['lib/tasks/*.rake'].each { |rake| load rake }
-
-require "rubygems"
-require "bundler/setup"
-require 'rspec/core/rake_task'
-
-RSpec::Core::RakeTask.new(:spec)
-
-task :test => :spec
-task :default => :spec
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+Dir['lib/tasks/*.rake'].each { |rake| load rake }
+
+require "rubygems"
+require "bundler/setup"
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :test => :spec
+task :default => :spec
+
View
966 app/assets/javascripts/rails_admin/jquery.colorpicker.js
@@ -1,484 +1,484 @@
-/**
- *
- * Color picker
- * Author: Stefan Petre www.eyecon.ro
- *
- * Dual licensed under the MIT and GPL licenses
- *
- */
-(function ($) {
- var ColorPicker = function () {
- var
- ids = {},
- inAction,
- charMin = 65,
- visible,
- tpl = '<div class="colorpicker"><div class="colorpicker_color"><div><div></div></div></div><div class="colorpicker_hue"><div></div></div><div class="colorpicker_new_color"></div><div class="colorpicker_current_color"></div><div class="colorpicker_hex"><input type="text" maxlength="6" size="6" /></div><div class="colorpicker_rgb_r colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_g colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_h colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_s colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_submit"></div></div>',
- defaults = {
- eventName: 'click',
- onShow: function () {},
- onBeforeShow: function(){},
- onHide: function () {},
- onChange: function () {},
- onSubmit: function () {},
- color: 'ff0000',
- livePreview: true,
- flat: false
- },
- fillRGBFields = function (hsb, cal) {
- var rgb = HSBToRGB(hsb);
- $(cal).data('colorpicker').fields
- .eq(1).val(rgb.r).end()
- .eq(2).val(rgb.g).end()
- .eq(3).val(rgb.b).end();
- },
- fillHSBFields = function (hsb, cal) {
- $(cal).data('colorpicker').fields
- .eq(4).val(hsb.h).end()
- .eq(5).val(hsb.s).end()
- .eq(6).val(hsb.b).end();
- },
- fillHexFields = function (hsb, cal) {
- $(cal).data('colorpicker').fields
- .eq(0).val(HSBToHex(hsb)).end();
- },
- setSelector = function (hsb, cal) {
- $(cal).data('colorpicker').selector.css('backgroundColor', '#' + HSBToHex({h: hsb.h, s: 100, b: 100}));
- $(cal).data('colorpicker').selectorIndic.css({
- left: parseInt(150 * hsb.s/100, 10),
- top: parseInt(150 * (100-hsb.b)/100, 10)
- });
- },
- setHue = function (hsb, cal) {
- $(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h/360, 10));
- },
- setCurrentColor = function (hsb, cal) {
- $(cal).data('colorpicker').currentColor.css('backgroundColor', '#' + HSBToHex(hsb));
- },
- setNewColor = function (hsb, cal) {
- $(cal).data('colorpicker').newColor.css('backgroundColor', '#' + HSBToHex(hsb));
- },
- keyDown = function (ev) {
- var pressedKey = ev.charCode || ev.keyCode || -1;
- if ((pressedKey > charMin && pressedKey <= 90) || pressedKey == 32) {
- return false;
- }
- var cal = $(this).parent().parent();
- if (cal.data('colorpicker').livePreview === true) {
- change.apply(this);
- }
- },
- change = function (ev) {
- var cal = $(this).parent().parent(), col;
- if (this.parentNode.className.indexOf('_hex') > 0) {
- cal.data('colorpicker').color = col = HexToHSB(fixHex(this.value));
- } else if (this.parentNode.className.indexOf('_hsb') > 0) {
- cal.data('colorpicker').color = col = fixHSB({
- h: parseInt(cal.data('colorpicker').fields.eq(4).val(), 10),
- s: parseInt(cal.data('colorpicker').fields.eq(5).val(), 10),
- b: parseInt(cal.data('colorpicker').fields.eq(6).val(), 10)
- });
- } else {
- cal.data('colorpicker').color = col = RGBToHSB(fixRGB({
- r: parseInt(cal.data('colorpicker').fields.eq(1).val(), 10),
- g: parseInt(cal.data('colorpicker').fields.eq(2).val(), 10),
- b: parseInt(cal.data('colorpicker').fields.eq(3).val(), 10)
- }));
- }
- if (ev) {
- fillRGBFields(col, cal.get(0));
- fillHexFields(col, cal.get(0));
- fillHSBFields(col, cal.get(0));
- }
- setSelector(col, cal.get(0));
- setHue(col, cal.get(0));
- setNewColor(col, cal.get(0));
- cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col)]);
- },
- blur = function (ev) {
- var cal = $(this).parent().parent();
- cal.data('colorpicker').fields.parent().removeClass('colorpicker_focus');
- },
- focus = function () {
- charMin = this.parentNode.className.indexOf('_hex') > 0 ? 70 : 65;
- $(this).parent().parent().data('colorpicker').fields.parent().removeClass('colorpicker_focus');
- $(this).parent().addClass('colorpicker_focus');
- },
- downIncrement = function (ev) {
- var field = $(this).parent().find('input').focus();
- var current = {
- el: $(this).parent().addClass('colorpicker_slider'),
- max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255),
- y: ev.pageY,
- field: field,
- val: parseInt(field.val(), 10),
- preview: $(this).parent().parent().data('colorpicker').livePreview
- };
- $(document).bind('mouseup', current, upIncrement);
- $(document).bind('mousemove', current, moveIncrement);
- },
- moveIncrement = function (ev) {
- ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val + ev.pageY - ev.data.y, 10))));
- if (ev.data.preview) {
- change.apply(ev.data.field.get(0), [true]);
- }
- return false;
- },
- upIncrement = function (ev) {
- change.apply(ev.data.field.get(0), [true]);
- ev.data.el.removeClass('colorpicker_slider').find('input').focus();
- $(document).unbind('mouseup', upIncrement);
- $(document).unbind('mousemove', moveIncrement);
- return false;
- },
- downHue = function (ev) {
- var current = {
- cal: $(this).parent(),
- y: $(this).offset().top
- };
- current.preview = current.cal.data('colorpicker').livePreview;
- $(document).bind('mouseup', current, upHue);
- $(document).bind('mousemove', current, moveHue);
- },
- moveHue = function (ev) {
- change.apply(
- ev.data.cal.data('colorpicker')
- .fields
- .eq(4)
- .val(parseInt(360*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.y))))/150, 10))
- .get(0),
- [ev.data.preview]
- );
- return false;
- },
- upHue = function (ev) {
- fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
- fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
- $(document).unbind('mouseup', upHue);
- $(document).unbind('mousemove', moveHue);
- return false;
- },
- downSelector = function (ev) {
- var current = {
- cal: $(this).parent(),
- pos: $(this).offset()
- };
- current.preview = current.cal.data('colorpicker').livePreview;
- $(document).bind('mouseup', current, upSelector);
- $(document).bind('mousemove', current, moveSelector);
- },
- moveSelector = function (ev) {
- change.apply(
- ev.data.cal.data('colorpicker')
- .fields
- .eq(6)
- .val(parseInt(100*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.pos.top))))/150, 10))
- .end()
- .eq(5)
- .val(parseInt(100*(Math.max(0,Math.min(150,(ev.pageX - ev.data.pos.left))))/150, 10))
- .get(0),
- [ev.data.preview]
- );
- return false;
- },
- upSelector = function (ev) {
- fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
- fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
- $(document).unbind('mouseup', upSelector);
- $(document).unbind('mousemove', moveSelector);
- return false;
- },
- enterSubmit = function (ev) {
- $(this).addClass('colorpicker_focus');
- },
- leaveSubmit = function (ev) {
- $(this).removeClass('colorpicker_focus');
- },
- clickSubmit = function (ev) {
- var cal = $(this).parent();
- var col = cal.data('colorpicker').color;
- cal.data('colorpicker').origColor = col;
- setCurrentColor(col, cal.get(0));
- cal.data('colorpicker').onSubmit(col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el);
- },
- show = function (ev) {
- var cal = $('#' + $(this).data('colorpickerId'));
- cal.data('colorpicker').onBeforeShow.apply(this, [cal.get(0)]);
- var pos = $(this).offset();
- var viewPort = getViewport();
- var top = pos.top + this.offsetHeight;
- var left = pos.left;
- if (top + 176 > viewPort.t + viewPort.h) {
- top -= this.offsetHeight + 176;
- }
- if (left + 356 > viewPort.l + viewPort.w) {
- left -= 356;
- }
- cal.css({left: left + 'px', top: top + 'px'});
- if (cal.data('colorpicker').onShow.apply(this, [cal.get(0)]) != false) {
- cal.show();
- }
- $(document).bind('mousedown', {cal: cal}, hide);
- return false;
- },
- hide = function (ev) {
- if (!isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
- if (ev.data.cal.data('colorpicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
- ev.data.cal.hide();
- }
- $(document).unbind('mousedown', hide);
- }
- },
- isChildOf = function(parentEl, el, container) {
- if (parentEl == el) {
- return true;
- }
- if (parentEl.contains) {
- return parentEl.contains(el);
- }
- if ( parentEl.compareDocumentPosition ) {
- return !!(parentEl.compareDocumentPosition(el) & 16);
- }
- var prEl = el.parentNode;
- while(prEl && prEl != container) {
- if (prEl == parentEl)
- return true;
- prEl = prEl.parentNode;
- }
- return false;
- },
- getViewport = function () {
- var m = document.compatMode == 'CSS1Compat';
- return {
- l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
- t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
- w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
- h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
- };
- },
- fixHSB = function (hsb) {
- return {
- h: Math.min(360, Math.max(0, hsb.h)),
- s: Math.min(100, Math.max(0, hsb.s)),
- b: Math.min(100, Math.max(0, hsb.b))
- };
- },
- fixRGB = function (rgb) {
- return {
- r: Math.min(255, Math.max(0, rgb.r)),
- g: Math.min(255, Math.max(0, rgb.g)),
- b: Math.min(255, Math.max(0, rgb.b))
- };
- },
- fixHex = function (hex) {
- var len = 6 - hex.length;
- if (len > 0) {
- var o = [];
- for (var i=0; i<len; i++) {
- o.push('0');
- }
- o.push(hex);
- hex = o.join('');
- }
- return hex;
- },
- HexToRGB = function (hex) {
- var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
- return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
- },
- HexToHSB = function (hex) {
- return RGBToHSB(HexToRGB(hex));
- },
- RGBToHSB = function (rgb) {
- var hsb = {
- h: 0,
- s: 0,
- b: 0
- };
- var min = Math.min(rgb.r, rgb.g, rgb.b);
- var max = Math.max(rgb.r, rgb.g, rgb.b);
- var delta = max - min;
- hsb.b = max;
- if (max != 0) {
-
- }
- hsb.s = max != 0 ? 255 * delta / max : 0;
- if (hsb.s != 0) {
- if (rgb.r == max) {
- hsb.h = (rgb.g - rgb.b) / delta;
- } else if (rgb.g == max) {
- hsb.h = 2 + (rgb.b - rgb.r) / delta;
- } else {
- hsb.h = 4 + (rgb.r - rgb.g) / delta;
- }
- } else {
- hsb.h = -1;
- }
- hsb.h *= 60;
- if (hsb.h < 0) {
- hsb.h += 360;
- }
- hsb.s *= 100/255;
- hsb.b *= 100/255;
- return hsb;
- },
- HSBToRGB = function (hsb) {
- var rgb = {};
- var h = Math.round(hsb.h);
- var s = Math.round(hsb.s*255/100);
- var v = Math.round(hsb.b*255/100);
- if(s == 0) {
- rgb.r = rgb.g = rgb.b = v;
- } else {
- var t1 = v;
- var t2 = (255-s)*v/255;
- var t3 = (t1-t2)*(h%60)/60;
- if(h==360) h = 0;
- if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
- else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
- else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
- else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
- else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
- else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
- else {rgb.r=0; rgb.g=0; rgb.b=0}
- }
- return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
- },
- RGBToHex = function (rgb) {
- var hex = [
- rgb.r.toString(16),
- rgb.g.toString(16),
- rgb.b.toString(16)
- ];
- $.each(hex, function (nr, val) {
- if (val.length == 1) {
- hex[nr] = '0' + val;
- }
- });
- return hex.join('');
- },
- HSBToHex = function (hsb) {
- return RGBToHex(HSBToRGB(hsb));
- },
- restoreOriginal = function () {
- var cal = $(this).parent();
- var col = cal.data('colorpicker').origColor;
- cal.data('colorpicker').color = col;
- fillRGBFields(col, cal.get(0));
- fillHexFields(col, cal.get(0));
- fillHSBFields(col, cal.get(0));
- setSelector(col, cal.get(0));
- setHue(col, cal.get(0));
- setNewColor(col, cal.get(0));
- };
- return {
- init: function (opt) {
- opt = $.extend({}, defaults, opt||{});
- if (typeof opt.color == 'string') {
- opt.color = HexToHSB(opt.color);
- } else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) {
- opt.color = RGBToHSB(opt.color);
- } else if (opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined) {
- opt.color = fixHSB(opt.color);
- } else {
- return this;
- }
- return this.each(function () {
- if (!$(this).data('colorpickerId')) {
- var options = $.extend({}, opt);
- options.origColor = opt.color;
- var id = 'collorpicker_' + parseInt(Math.random() * 1000);
- $(this).data('colorpickerId', id);
- var cal = $(tpl).attr('id', id);
- if (options.flat) {
- cal.appendTo(this).show();
- } else {
- cal.appendTo(document.body);
- }
- options.fields = cal
- .find('input')
- .bind('keyup', keyDown)
- .bind('change', change)
- .bind('blur', blur)
- .bind('focus', focus);
- cal
- .find('span').bind('mousedown', downIncrement).end()
- .find('>div.colorpicker_current_color').bind('click', restoreOriginal);
- options.selector = cal.find('div.colorpicker_color').bind('mousedown', downSelector);
- options.selectorIndic = options.selector.find('div div');
- options.el = this;
- options.hue = cal.find('div.colorpicker_hue div');
- cal.find('div.colorpicker_hue').bind('mousedown', downHue);
- options.newColor = cal.find('div.colorpicker_new_color');
- options.currentColor = cal.find('div.colorpicker_current_color');
- cal.data('colorpicker', options);
- cal.find('div.colorpicker_submit')
- .bind('mouseenter', enterSubmit)
- .bind('mouseleave', leaveSubmit)
- .bind('click', clickSubmit);
- fillRGBFields(options.color, cal.get(0));
- fillHSBFields(options.color, cal.get(0));
- fillHexFields(options.color, cal.get(0));
- setHue(options.color, cal.get(0));
- setSelector(options.color, cal.get(0));
- setCurrentColor(options.color, cal.get(0));
- setNewColor(options.color, cal.get(0));
- if (options.flat) {
- cal.css({
- position: 'relative',
- display: 'block'
- });
- } else {
- $(this).bind(options.eventName, show);
- }
- }
- });
- },
- showPicker: function() {
- return this.each( function () {
- if ($(this).data('colorpickerId')) {
- show.apply(this);
- }
- });
- },
- hidePicker: function() {
- return this.each( function () {
- if ($(this).data('colorpickerId')) {
- $('#' + $(this).data('colorpickerId')).hide();
- }
- });
- },
- setColor: function(col) {
- if (typeof col == 'string') {
- col = HexToHSB(col);
- } else if (col.r != undefined && col.g != undefined && col.b != undefined) {
- col = RGBToHSB(col);
- } else if (col.h != undefined && col.s != undefined && col.b != undefined) {
- col = fixHSB(col);
- } else {
- return this;
- }
- return this.each(function(){
- if ($(this).data('colorpickerId')) {
- var cal = $('#' + $(this).data('colorpickerId'));
- cal.data('colorpicker').color = col;
- cal.data('colorpicker').origColor = col;
- fillRGBFields(col, cal.get(0));
- fillHSBFields(col, cal.get(0));
- fillHexFields(col, cal.get(0));
- setHue(col, cal.get(0));
- setSelector(col, cal.get(0));
- setCurrentColor(col, cal.get(0));
- setNewColor(col, cal.get(0));
- }
- });
- }
- };
- }();
- $.fn.extend({
- ColorPicker: ColorPicker.init,
- ColorPickerHide: ColorPicker.hidePicker,
- ColorPickerShow: ColorPicker.showPicker,
- ColorPickerSetColor: ColorPicker.setColor
- });
+/**
+ *
+ * Color picker
+ * Author: Stefan Petre www.eyecon.ro
+ *
+ * Dual licensed under the MIT and GPL licenses
+ *
+ */
+(function ($) {
+ var ColorPicker = function () {
+ var
+ ids = {},
+ inAction,
+ charMin = 65,
+ visible,
+ tpl = '<div class="colorpicker"><div class="colorpicker_color"><div><div></div></div></div><div class="colorpicker_hue"><div></div></div><div class="colorpicker_new_color"></div><div class="colorpicker_current_color"></div><div class="colorpicker_hex"><input type="text" maxlength="6" size="6" /></div><div class="colorpicker_rgb_r colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_g colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_h colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_s colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_submit"></div></div>',
+ defaults = {
+ eventName: 'click',
+ onShow: function () {},
+ onBeforeShow: function(){},
+ onHide: function () {},
+ onChange: function () {},
+ onSubmit: function () {},
+ color: 'ff0000',
+ livePreview: true,
+ flat: false
+ },
+ fillRGBFields = function (hsb, cal) {
+ var rgb = HSBToRGB(hsb);
+ $(cal).data('colorpicker').fields
+ .eq(1).val(rgb.r).end()
+ .eq(2).val(rgb.g).end()
+ .eq(3).val(rgb.b).end();
+ },
+ fillHSBFields = function (hsb, cal) {
+ $(cal).data('colorpicker').fields
+ .eq(4).val(hsb.h).end()
+ .eq(5).val(hsb.s).end()
+ .eq(6).val(hsb.b).end();
+ },
+ fillHexFields = function (hsb, cal) {
+ $(cal).data('colorpicker').fields
+ .eq(0).val(HSBToHex(hsb)).end();
+ },
+ setSelector = function (hsb, cal) {
+ $(cal).data('colorpicker').selector.css('backgroundColor', '#' + HSBToHex({h: hsb.h, s: 100, b: 100}));
+ $(cal).data('colorpicker').selectorIndic.css({
+ left: parseInt(150 * hsb.s/100, 10),
+ top: parseInt(150 * (100-hsb.b)/100, 10)
+ });
+ },
+ setHue = function (hsb, cal) {
+ $(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h/360, 10));
+ },
+ setCurrentColor = function (hsb, cal) {
+ $(cal).data('colorpicker').currentColor.css('backgroundColor', '#' + HSBToHex(hsb));
+ },
+ setNewColor = function (hsb, cal) {
+ $(cal).data('colorpicker').newColor.css('backgroundColor', '#' + HSBToHex(hsb));
+ },
+ keyDown = function (ev) {
+ var pressedKey = ev.charCode || ev.keyCode || -1;
+ if ((pressedKey > charMin && pressedKey <= 90) || pressedKey == 32) {
+ return false;
+ }
+ var cal = $(this).parent().parent();
+ if (cal.data('colorpicker').livePreview === true) {
+ change.apply(this);
+ }
+ },
+ change = function (ev) {
+ var cal = $(this).parent().parent(), col;
+ if (this.parentNode.className.indexOf('_hex') > 0) {
+ cal.data('colorpicker').color = col = HexToHSB(fixHex(this.value));
+ } else if (this.parentNode.className.indexOf('_hsb') > 0) {
+ cal.data('colorpicker').color = col = fixHSB({
+ h: parseInt(cal.data('colorpicker').fields.eq(4).val(), 10),
+ s: parseInt(cal.data('colorpicker').fields.eq(5).val(), 10),
+ b: parseInt(cal.data('colorpicker').fields.eq(6).val(), 10)
+ });
+ } else {
+ cal.data('colorpicker').color = col = RGBToHSB(fixRGB({
+ r: parseInt(cal.data('colorpicker').fields.eq(1).val(), 10),
+ g: parseInt(cal.data('colorpicker').fields.eq(2).val(), 10),
+ b: parseInt(cal.data('colorpicker').fields.eq(3).val(), 10)
+ }));
+ }
+ if (ev) {
+ fillRGBFields(col, cal.get(0));
+ fillHexFields(col, cal.get(0));
+ fillHSBFields(col, cal.get(0));
+ }
+ setSelector(col, cal.get(0));
+ setHue(col, cal.get(0));
+ setNewColor(col, cal.get(0));
+ cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col)]);
+ },
+ blur = function (ev) {
+ var cal = $(this).parent().parent();
+ cal.data('colorpicker').fields.parent().removeClass('colorpicker_focus');
+ },
+ focus = function () {
+ charMin = this.parentNode.className.indexOf('_hex') > 0 ? 70 : 65;
+ $(this).parent().parent().data('colorpicker').fields.parent().removeClass('colorpicker_focus');
+ $(this).parent().addClass('colorpicker_focus');
+ },
+ downIncrement = function (ev) {
+ var field = $(this).parent().find('input').focus();
+ var current = {
+ el: $(this).parent().addClass('colorpicker_slider'),
+ max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255),
+ y: ev.pageY,
+ field: field,
+ val: parseInt(field.val(), 10),
+ preview: $(this).parent().parent().data('colorpicker').livePreview
+ };
+ $(document).bind('mouseup', current, upIncrement);
+ $(document).bind('mousemove', current, moveIncrement);
+ },
+ moveIncrement = function (ev) {
+ ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val + ev.pageY - ev.data.y, 10))));
+ if (ev.data.preview) {
+ change.apply(ev.data.field.get(0), [true]);
+ }
+ return false;
+ },
+ upIncrement = function (ev) {
+ change.apply(ev.data.field.get(0), [true]);
+ ev.data.el.removeClass('colorpicker_slider').find('input').focus();
+ $(document).unbind('mouseup', upIncrement);
+ $(document).unbind('mousemove', moveIncrement);
+ return false;
+ },
+ downHue = function (ev) {
+ var current = {
+ cal: $(this).parent(),
+ y: $(this).offset().top
+ };
+ current.preview = current.cal.data('colorpicker').livePreview;
+ $(document).bind('mouseup', current, upHue);
+ $(document).bind('mousemove', current, moveHue);
+ },
+ moveHue = function (ev) {
+ change.apply(
+ ev.data.cal.data('colorpicker')
+ .fields
+ .eq(4)
+ .val(parseInt(360*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.y))))/150, 10))
+ .get(0),
+ [ev.data.preview]
+ );
+ return false;
+ },
+ upHue = function (ev) {
+ fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
+ fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
+ $(document).unbind('mouseup', upHue);
+ $(document).unbind('mousemove', moveHue);
+ return false;
+ },
+ downSelector = function (ev) {
+ var current = {
+ cal: $(this).parent(),
+ pos: $(this).offset()
+ };
+ current.preview = current.cal.data('colorpicker').livePreview;
+ $(document).bind('mouseup', current, upSelector);
+ $(document).bind('mousemove', current, moveSelector);
+ },
+ moveSelector = function (ev) {
+ change.apply(
+ ev.data.cal.data('colorpicker')
+ .fields
+ .eq(6)
+ .val(parseInt(100*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.pos.top))))/150, 10))
+ .end()
+ .eq(5)
+ .val(parseInt(100*(Math.max(0,Math.min(150,(ev.pageX - ev.data.pos.left))))/150, 10))
+ .get(0),
+ [ev.data.preview]
+ );
+ return false;
+ },
+ upSelector = function (ev) {
+ fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
+ fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
+ $(document).unbind('mouseup', upSelector);
+ $(document).unbind('mousemove', moveSelector);
+ return false;
+ },
+ enterSubmit = function (ev) {
+ $(this).addClass('colorpicker_focus');
+ },
+ leaveSubmit = function (ev) {
+ $(this).removeClass('colorpicker_focus');
+ },
+ clickSubmit = function (ev) {
+ var cal = $(this).parent();
+ var col = cal.data('colorpicker').color;
+ cal.data('colorpicker').origColor = col;
+ setCurrentColor(col, cal.get(0));
+ cal.data('colorpicker').onSubmit(col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el);
+ },
+ show = function (ev) {
+ var cal = $('#' + $(this).data('colorpickerId'));
+ cal.data('colorpicker').onBeforeShow.apply(this, [cal.get(0)]);
+ var pos = $(this).offset();
+ var viewPort = getViewport();
+ var top = pos.top + this.offsetHeight;
+ var left = pos.left;
+ if (top + 176 > viewPort.t + viewPort.h) {
+ top -= this.offsetHeight + 176;
+ }
+ if (left + 356 > viewPort.l + viewPort.w) {
+ left -= 356;
+ }
+ cal.css({left: left + 'px', top: top + 'px'});
+ if (cal.data('colorpicker').onShow.apply(this, [cal.get(0)]) != false) {
+ cal.show();
+ }
+ $(document).bind('mousedown', {cal: cal}, hide);
+ return false;
+ },
+ hide = function (ev) {
+ if (!isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
+ if (ev.data.cal.data('colorpicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
+ ev.data.cal.hide();
+ }
+ $(document).unbind('mousedown', hide);
+ }
+ },
+ isChildOf = function(parentEl, el, container) {
+ if (parentEl == el) {
+ return true;
+ }
+ if (parentEl.contains) {
+ return parentEl.contains(el);
+ }
+ if ( parentEl.compareDocumentPosition ) {
+ return !!(parentEl.compareDocumentPosition(el) & 16);
+ }
+ var prEl = el.parentNode;
+ while(prEl && prEl != container) {
+ if (prEl == parentEl)
+ return true;
+ prEl = prEl.parentNode;
+ }
+ return false;
+ },
+ getViewport = function () {
+ var m = document.compatMode == 'CSS1Compat';
+ return {
+ l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
+ t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
+ w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
+ h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
+ };
+ },
+ fixHSB = function (hsb) {
+ return {
+ h: Math.min(360, Math.max(0, hsb.h)),
+ s: Math.min(100, Math.max(0, hsb.s)),
+ b: Math.min(100, Math.max(0, hsb.b))
+ };
+ },
+ fixRGB = function (rgb) {
+ return {
+ r: Math.min(255, Math.max(0, rgb.r)),
+ g: Math.min(255, Math.max(0, rgb.g)),
+ b: Math.min(255, Math.max(0, rgb.b))
+ };
+ },
+ fixHex = function (hex) {
+ var len = 6 - hex.length;
+ if (len > 0) {
+ var o = [];
+ for (var i=0; i<len; i++) {
+ o.push('0');
+ }
+ o.push(hex);
+ hex = o.join('');
+ }
+ return hex;
+ },
+ HexToRGB = function (hex) {
+ var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
+ return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
+ },
+ HexToHSB = function (hex) {
+ return RGBToHSB(HexToRGB(hex));
+ },
+ RGBToHSB = function (rgb) {
+ var hsb = {
+ h: 0,
+ s: 0,
+ b: 0
+ };
+ var min = Math.min(rgb.r, rgb.g, rgb.b);
+ var max = Math.max(rgb.r, rgb.g, rgb.b);
+ var delta = max - min;
+ hsb.b = max;
+ if (max != 0) {
+
+ }
+ hsb.s = max != 0 ? 255 * delta / max : 0;
+ if (hsb.s != 0) {
+ if (rgb.r == max) {
+ hsb.h = (rgb.g - rgb.b) / delta;
+ } else if (rgb.g == max) {
+ hsb.h = 2 + (rgb.b - rgb.r) / delta;
+ } else {
+ hsb.h = 4 + (rgb.r - rgb.g) / delta;
+ }
+ } else {
+ hsb.h = -1;
+ }
+ hsb.h *= 60;
+ if (hsb.h < 0) {
+ hsb.h += 360;
+ }
+ hsb.s *= 100/255;
+ hsb.b *= 100/255;
+ return hsb;
+ },
+ HSBToRGB = function (hsb) {
+ var rgb = {};
+ var h = Math.round(hsb.h);
+ var s = Math.round(hsb.s*255/100);
+ var v = Math.round(hsb.b*255/100);
+ if(s == 0) {
+ rgb.r = rgb.g = rgb.b = v;
+ } else {
+ var t1 = v;
+ var t2 = (255-s)*v/255;
+ var t3 = (t1-t2)*(h%60)/60;
+ if(h==360) h = 0;
+ if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
+ else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
+ else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
+ else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
+ else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
+ else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
+ else {rgb.r=0; rgb.g=0; rgb.b=0}
+ }
+ return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
+ },
+ RGBToHex = function (rgb) {
+ var hex = [
+ rgb.r.toString(16),
+ rgb.g.toString(16),
+ rgb.b.toString(16)
+ ];
+ $.each(hex, function (nr, val) {
+ if (val.length == 1) {
+ hex[nr] = '0' + val;
+ }
+ });
+ return hex.join('');
+ },
+ HSBToHex = function (hsb) {
+ return RGBToHex(HSBToRGB(hsb));
+ },
+ restoreOriginal = function () {
+ var cal = $(this).parent();
+ var col = cal.data('colorpicker').origColor;
+ cal.data('colorpicker').color = col;
+ fillRGBFields(col, cal.get(0));
+ fillHexFields(col, cal.get(0));
+ fillHSBFields(col, cal.get(0));
+ setSelector(col, cal.get(0));
+ setHue(col, cal.get(0));
+ setNewColor(col, cal.get(0));
+ };
+ return {
+ init: function (opt) {
+ opt = $.extend({}, defaults, opt||{});
+ if (typeof opt.color == 'string') {
+ opt.color = HexToHSB(opt.color);
+ } else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) {
+ opt.color = RGBToHSB(opt.color);
+ } else if (opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined) {
+ opt.color = fixHSB(opt.color);
+ } else {
+ return this;
+ }
+ return this.each(function () {
+ if (!$(this).data('colorpickerId')) {
+ var options = $.extend({}, opt);
+ options.origColor = opt.color;
+ var id = 'collorpicker_' + parseInt(Math.random() * 1000);
+ $(this).data('colorpickerId', id);
+ var cal = $(tpl).attr('id', id);
+ if (options.flat) {
+ cal.appendTo(this).show();
+ } else {
+ cal.appendTo(document.body);
+ }
+ options.fields = cal
+ .find('input')
+ .bind('keyup', keyDown)
+ .bind('change', change)
+ .bind('blur', blur)
+ .bind('focus', focus);
+ cal
+ .find('span').bind('mousedown', downIncrement).end()
+ .find('>div.colorpicker_current_color').bind('click', restoreOriginal);
+ options.selector = cal.find('div.colorpicker_color').bind('mousedown', downSelector);
+ options.selectorIndic = options.selector.find('div div');
+ options.el = this;
+ options.hue = cal.find('div.colorpicker_hue div');
+ cal.find('div.colorpicker_hue').bind('mousedown', downHue);
+ options.newColor = cal.find('div.colorpicker_new_color');
+ options.currentColor = cal.find('div.colorpicker_current_color');
+ cal.data('colorpicker', options);
+ cal.find('div.colorpicker_submit')
+ .bind('mouseenter', enterSubmit)
+ .bind('mouseleave', leaveSubmit)
+ .bind('click', clickSubmit);
+ fillRGBFields(options.color, cal.get(0));
+ fillHSBFields(options.color, cal.get(0));
+ fillHexFields(options.color, cal.get(0));
+ setHue(options.color, cal.get(0));
+ setSelector(options.color, cal.get(0));
+ setCurrentColor(options.color, cal.get(0));
+ setNewColor(options.color, cal.get(0));
+ if (options.flat) {
+ cal.css({
+ position: 'relative',
+ display: 'block'
+ });
+ } else {
+ $(this).bind(options.eventName, show);
+ }
+ }
+ });
+ },
+ showPicker: function() {
+ return this.each( function () {
+ if ($(this).data('colorpickerId')) {
+ show.apply(this);
+ }
+ });
+ },
+ hidePicker: function() {
+ return this.each( function () {
+ if ($(this).data('colorpickerId')) {
+ $('#' + $(this).data('colorpickerId')).hide();
+ }
+ });
+ },
+ setColor: function(col) {
+ if (typeof col == 'string') {
+ col = HexToHSB(col);
+ } else if (col.r != undefined && col.g != undefined && col.b != undefined) {
+ col = RGBToHSB(col);
+ } else if (col.h != undefined && col.s != undefined && col.b != undefined) {
+ col = fixHSB(col);
+ } else {
+ return this;
+ }
+ return this.each(function(){
+ if ($(this).data('colorpickerId')) {
+ var cal = $('#' + $(this).data('colorpickerId'));
+ cal.data('colorpicker').color = col;
+ cal.data('colorpicker').origColor = col;
+ fillRGBFields(col, cal.get(0));
+ fillHSBFields(col, cal.get(0));
+ fillHexFields(col, cal.get(0));
+ setHue(col, cal.get(0));
+ setSelector(col, cal.get(0));
+ setCurrentColor(col, cal.get(0));
+ setNewColor(col, cal.get(0));
+ }
+ });
+ }
+ };
+ }();
+ $.fn.extend({
+ ColorPicker: ColorPicker.init,
+ ColorPickerHide: ColorPicker.hidePicker,
+ ColorPickerShow: ColorPicker.showPicker,
+ ColorPickerSetColor: ColorPicker.setColor
+ });
})(jQuery)
View
2,438 app/assets/javascripts/rails_admin/jquery.ui.timepicker.js
1,219 additions, 1,219 deletions not shown
View
4 app/assets/stylesheets/rails_admin/base/README
@@ -1,2 +1,2 @@
-For RailsAdmin developpers;
-We should use sass variables & mixins as much as possible so that themers/users can override them cleanly
+For RailsAdmin developpers;
+We should use sass variables & mixins as much as possible so that themers/users can override them cleanly
View
222 config/locales/rails_admin.pl.yml
@@ -1,111 +1,111 @@
-# Sample localization file for English. Add more files in this directory for other locales.
-# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
-
-pl:
- home:
- name: "start"
- views:
- pagination:
- previous: "&laquo; Prev"
- next: "Next &raquo;"
- truncate: ""
- admin:
- dashboard:
- pagename: "Panel administracyjny"
- name: "Pulpit"
- model_name: "Model"
- last_used: "Data zmian"
- records: "Liczba rekordów"
- modify: "Akcja"
- add_new: "Dodaj nowy"
- show: "pokaż"
- ago: "temu"
- navigation: "Menu"
- history:
- name: "Historia"
- page_name: "Historia zmian modelu %{name}"
- no_activity: "Brak zmian"
- show:
- show_in_app: "Pokaż na stronie"
- page_name: "%{name} – szczegóły"
- no_file_found: "Nie znaleziono pliku"
- credentials:
- log_out: "Wyloguj się"
- index:
- edit_action: "Edytuj"
- delete_action: "Usuń"
- select_action: "Select"
- export_action: "Eksportuj aktualny widok"
- show_action: "Pokaż"
- export_selected: "Eksportuj zaznaczone"
- delete_selected: "Usuń zaznaczone"
- add_new: "Dodaj"
- search: "SZUKAJ"
- select: "Wybierz %{name} do edycji"
- show_all: "Wybierz wszystkie"
- add_filter: "Dodaj filtr"
- new:
- basic_info: "Atrybuty"
- required: "Wymagane"
- optional: "Opcjonalnie"
- one_char: "znak"
- many_chars: "znaków lub mniej"
- chosen: "Wybrane %{name}"
- select_choice: "Wybierz kilka i kliknij"
- chose_all: "Wybierz wszystkie"
- clear_all: "Wyczyść"
- up: "Góra"
- down: "Dół"
- save: "Zapisz"
- save_and_add_another: "Zapisz i dodaj kolejny"
- save_and_edit: "Zapisz i wróć do edycji"
- cancel: "Anuluj"
- delete:
- all_of_the_following_related_items_will_be_deleted: "? Wszystkie następujące powiązane elementy zostaną usunięte:"
- are_you_sure_you_want_to_delete_the_object: "Czy masz pewność, że chcesz usunąć %{model_name}"
- confirmation: "Tak, jestem pewien."
- delete_confirmation: "Potwierdzenie usunięcia"
- bulk_delete: "Następujące elementy zostaną usunięte, co może skutkować zarówno usunięciem jak i zepsuciem zależnych od nich elementów:"
- export:
- confirmation: "Eksportuj do %{name}"
- select: "Wybierz pola do eksportu"
- fields_from: "Pola dla %{name}"
- fields_from_associated: "Pola dla powiązanego %{name}"
- display: "Wyświetl %{name}: %{type}"
- options_for: "Opcje dla: %{name}"
- empty_value_for_associated_objects: "<empty>"
- csv:
- header_for_root_methods: "%{name}" # 'model' is available
- header_for_association_methods: "%{name} [%{association}]"
- encoding_to: "Kodowanie"
- encoding_to_help: "Wybierz docelowe kodowanie. Pozostaw puste by użyć obecnego kodowania: (%{name})"
- skip_header: "Brak nagłówka"
- skip_header_help: "Nie wyświetlaj nagłówka (brak opisu pól)"
- default_col_sep: ","
- col_sep: "Separator kolumn"
- col_sep_help: "Pozostaw puste by użyć wartości domyślnej ('%{value}')" # value is default_col_sep
- flash:
- successful: "%{name} został %{action}"
- error: "%{name} nie został %{action}"
- noaction: "Nie się nie stało"
- actions:
- create: "dodaj"
- created: "dodany"
- update: "zapisz"
- updated: "zapisany"
- delete: "usuń"
- deleted: "usunięty"
- export: "eksportuj"
- exported: "wyeksportowane"
- breadcrumbs:
- show: "pokaż"
- delete: "usuń"
- for_object: "historia"
- edit: "edytuj"
- export: "eksportuj"
- bulk_destroy: "usuń"
- new: "nowy"
- for_model: "historia"
- index: "lista"
- dashboard: "tablica"
-
+# Sample localization file for English. Add more files in this directory for other locales.
+# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+pl:
+ home:
+ name: "start"
+ views:
+ pagination:
+ previous: "&laquo; Prev"
+ next: "Next &raquo;"
+ truncate: ""
+ admin:
+ dashboard:
+ pagename: "Panel administracyjny"
+ name: "Pulpit"
+ model_name: "Model"
+ last_used: "Data zmian"
+ records: "Liczba rekordów"
+ modify: "Akcja"
+ add_new: "Dodaj nowy"
+ show: "pokaż"
+ ago: "temu"
+ navigation: "Menu"
+ history:
+ name: "Historia"
+ page_name: "Historia zmian modelu %{name}"
+ no_activity: "Brak zmian"
+ show:
+ show_in_app: "Pokaż na stronie"
+ page_name: "%{name} – szczegóły"
+ no_file_found: "Nie znaleziono pliku"
+ credentials:
+ log_out: "Wyloguj się"
+ index:
+ edit_action: "Edytuj"
+ delete_action: "Usuń"
+ select_action: "Select"
+ export_action: "Eksportuj aktualny widok"
+ show_action: "Pokaż"
+ export_selected: "Eksportuj zaznaczone"
+ delete_selected: "Usuń zaznaczone"
+ add_new: "Dodaj"
+ search: "SZUKAJ"
+ select: "Wybierz %{name} do edycji"
+ show_all: "Wybierz wszystkie"
+ add_filter: "Dodaj filtr"
+ new:
+ basic_info: "Atrybuty"
+ required: "Wymagane"
+ optional: "Opcjonalnie"
+ one_char: "znak"
+ many_chars: "znaków lub mniej"
+ chosen: "Wybrane %{name}"
+ select_choice: "Wybierz kilka i kliknij"
+ chose_all: "Wybierz wszystkie"
+ clear_all: "Wyczyść"
+ up: "Góra"
+ down: "Dół"
+ save: "Zapisz"
+ save_and_add_another: "Zapisz i dodaj kolejny"
+ save_and_edit: "Zapisz i wróć do edycji"
+ cancel: "Anuluj"
+ delete:
+ all_of_the_following_related_items_will_be_deleted: "? Wszystkie następujące powiązane elementy zostaną usunięte:"
+ are_you_sure_you_want_to_delete_the_object: "Czy masz pewność, że chcesz usunąć %{model_name}"
+ confirmation: "Tak, jestem pewien."
+ delete_confirmation: "Potwierdzenie usunięcia"
+ bulk_delete: "Następujące elementy zostaną usunięte, co może skutkować zarówno usunięciem jak i zepsuciem zależnych od nich elementów:"
+ export:
+ confirmation: "Eksportuj do %{name}"
+ select: "Wybierz pola do eksportu"
+ fields_from: "Pola dla %{name}"
+ fields_from_associated: "Pola dla powiązanego %{name}"
+ display: "Wyświetl %{name}: %{type}"
+ options_for: "Opcje dla: %{name}"
+ empty_value_for_associated_objects: "<empty>"
+ csv:
+ header_for_root_methods: "%{name}" # 'model' is available
+ header_for_association_methods: "%{name} [%{association}]"
+ encoding_to: "Kodowanie"
+ encoding_to_help: "Wybierz docelowe kodowanie. Pozostaw puste by użyć obecnego kodowania: (%{name})"
+ skip_header: "Brak nagłówka"
+ skip_header_help: "Nie wyświetlaj nagłówka (brak opisu pól)"
+ default_col_sep: ","
+ col_sep: "Separator kolumn"
+ col_sep_help: "Pozostaw puste by użyć wartości domyślnej ('%{value}')" # value is default_col_sep
+ flash:
+ successful: "%{name} został %{action}"
+ error: "%{name} nie został %{action}"
+ noaction: "Nie się nie stało"
+ actions:
+ create: "dodaj"
+ created: "dodany"
+ update: "zapisz"
+ updated: "zapisany"
+ delete: "usuń"
+ deleted: "usunięty"
+ export: "eksportuj"
+ exported: "wyeksportowane"
+ breadcrumbs:
+ show: "pokaż"
+ delete: "usuń"
+ for_object: "historia"
+ edit: "edytuj"
+ export: "eksportuj"
+ bulk_destroy: "usuń"
+ new: "nowy"
+ for_model: "historia"
+ index: "lista"
+ dashboard: "tablica"
+
View
322 lib/generators/rails_admin/templates/initializer.erb
@@ -1,161 +1,161 @@
-# ooooooooo. o8o oooo .o. .o8 o8o
-# `888 `Y88. `"' `888 .888. "888 `"'
-# 888 .d88' .oooo. oooo 888 .oooo.o .8"888. .oooo888 ooo. .oo. .oo. oooo ooo. .oo.
-# 888ooo88P' `P )88b `888 888 d88( "8 .8' `888. d88' `888 `888P"Y88bP"Y88b `888 `888P"Y88b
-# 888`88b. .oP"888 888 888 `"Y88b. .88ooo8888. 888 888 888 888 888 888 888 888
-# 888 `88b. d8( 888 888 888 o. )88b .8' `888. 888 888 888 888 888 888 888 888
-# o888o o888o `Y888""8o o888o o888o 8""888P' o88o o8888o `Y8bod88P" o888o o888o o888o o888o o888o o888o
-
-# RailsAdmin config file. Generated on <%= DateTime.now.to_s(:long) %>
-# See github.com/sferik/rails_admin for more informations
-
-RailsAdmin.config do |config|
-
- config.current_user_method { current_<%= @model_name %> } # auto-generated
-
- # Set the admin name here (optional second array element will appear in a beautiful RailsAdmin red ©)
- config.main_app_name = ['<%= Rails.application.engine_name.titleize.chomp(' Application') %>', 'Admin']
- # or for a dynamic name:
- # config.main_app_name = Proc.new { |controller| [Rails.application.engine_name.titleize, controller.params['action'].titleize] }
-
- # ==> Authentication (before_filter)
- # This is run inside the controller instance so you can setup any authentication you need to.
- # By default, the authentication will run via warden if available.
- # and will run on the default user scope.
- # If you use devise, this will authenticate the same as authenticate_user!
- # Example Devise admin
- # RailsAdmin.config do |config|
- # config.authenticate_with do
- # authenticate_admin!
- # end
- # end
- # Example Custom Warden
- # RailsAdmin.config do |config|
- # config.authenticate_with do
- # warden.authenticate! :scope => :paranoid
- # end
- # end
-
- # ==> Authorization
- # Use cancan https://github.com/ryanb/cancan for authorization:
- # config.authorize_with :cancan
-
- # Or use simple custom authorization rule:
- # config.authorize_with do
- # redirect_to root_path unless warden.user.is_admin?
- # end
-
- # Use a specific role for ActiveModel's :attr_acessible :attr_protected
- # Default is :default
- # current_user is accessible in the block if you want to make it user specific.
- # config.attr_accessible_role { :default }
-
- # ==> Global show view settings
- # Display empty fields in show views
- # config.compact_show_view = false
-
- # ==> Global list view settings
- # Number of default rows per-page:
- # config.default_items_per_page = 50
-
- # ==> Included models
- # Add all excluded models here:
- # config.excluded_models << [<%= RailsAdmin::AbstractModel.all_models.map(&:name).join(', ') %>]
-
- # Add models here if you want to go 'whitelist mode':
- # config.included_models << [<%= RailsAdmin::AbstractModel.all_models.map(&:name).join(', ') %>]
-
- # Application wide tried label methods for models' instances
- # config.label_methods << [:description] # Default is [:name, :title]
-
- # ==> Global models configuration
- # config.models do
- # # Configuration here will affect all included models in all scopes, handle with care!
- #
- # list do
- # # Configuration here will affect all included models in list sections (same for show, export, edit, update, create)
- #
- # fields :name, :other_name do
- # # Configuration here will affect all fields named [:name, :other_name], in the list section, for all included models
- # end
- #
- # fields_of_type :date do
- # # Configuration here will affect all date fields, in the list section, for all included models. See README for a comprehensive type list.
- # end
- # end
- # end
- #
- # ==> Model specific configuration
- # Keep in mind that *all* configuration blocks are optional.
- # RailsAdmin will try his best to provide the best defaults for each section, for each field!
- # Try to override as few things as possible, in the most generic way. Try to avoid setting labels for models and attributes, use ActiveRecord I18n API instead.
- # Less code is better code!
- # config.model MyModel do
- # # Here goes your cross-section field configuration for ModelName.
- # object_label_method :name # Name of the method called for pretty printing an *instance* of ModelName
- # label 'My model' # Name of ModelName (smartly defaults to ActiveRecord's I18n API)
- # label_plural 'My models' # Same, plural
- # weight -1 # Navigation priority. Bigger is higher.
- # parent OtherModel # Set parent model for navigation. MyModel will be nested below. OtherModel will be on first position of the dropdown
- # navigation_label # Sets dropdown entry's name in navigation. Only for parents!
- # # Section specific configuration:
- # list do
- # filters [:id, :name] # Array of field names which filters should be shown by default in the table header
- # items_per_page 100 # Override default_items_per_page
- # sort_by :id # Sort column (default is primary key)
- # sort_reverse true # Sort direction (default is true for primary key, last created first)
- # # Here goes the fields configuration for the list view
- # end
- # show do
- # # Here goes the fields configuration for the show view
- # end
- # export do
- # # Here goes the fields configuration for the export view (CSV, yaml, XML)
- # end
- # edit do
- # # Here goes the fields configuration for the edit view (for create and update view)
- # end
- # create do
- # # Here goes the fields configuration for the create view, overriding edit section settings
- # end
- # update do
- # # Here goes the fields configuration for the update view, overriding edit section settings
- # end
- # end
-
-# fields configuration is described in the Readme, if you have other question, ask us on the mailing-list!
-
-# ==> Your models configuration, to help you get started!
-<% RailsAdmin::AbstractModel.all.map do |abstract_model| -%>
-
-# All fields marked as 'hidden' won't be shown anywhere in the rails_admin unless you mark them as visible.
-# There can be different reasons for that:
-# - belongs_to _id and _type (polymorphic) columns are hidden in favor of their associations
-# - associations are hidden if they have no matchable model found (model not included or non-existant)
-# - they are part of a bigger plan in a plugin (Devise/Paperclip) and hidden by contract
-# Some fields may be hidden depending on the section, if they aren't deemed suitable for display or edition on that section
-# - non-editable columns (:id, :created_at, ..) in edit sections
-# - has_many/has_one associations in list section (hidden by default for performance reasons)
-# Fields may also be marked as read_only (and thus not editable) if they are not mass-assignable by current_user
-
- # config.model <%= abstract_model.model.model_name %> do
- # # Found associations:
-<% RailsAdmin.config(abstract_model).export.fields.select{|f| f.association?}.each do |field| -%>
- # field <%= field.name.inspect %>, <%= field.type.inspect %><%= " # Hidden" unless field.visible? %>
-<% end -%>
- # # Found columns:
-<% RailsAdmin.config(abstract_model).export.fields.select{|f| !f.association?}.each do |field| -%>
- # field <%= field.name.inspect %>, <%= field.type.inspect %><%= " # Hidden" unless field.visible? %>
-<% end -%>
- # # Sections:
- # list do; end
- # export do; end
- # show do; end
- # edit do; end
- # create do; end
- # update do; end
- # end
-<% end %>
-end
-
-# You made it this far? You're looking for something that doesn't exist! Add it to RailsAdmin and send us a Pull Request!
+# ooooooooo. o8o oooo .o. .o8 o8o
+# `888 `Y88. `"' `888 .888. "888 `"'
+# 888 .d88' .oooo. oooo 888 .oooo.o .8"888. .oooo888 ooo. .oo. .oo. oooo ooo. .oo.
+# 888ooo88P' `P )88b `888 888 d88( "8 .8' `888. d88' `888 `888P"Y88bP"Y88b `888 `888P"Y88b
+# 888`88b. .oP"888 888 888 `"Y88b. .88ooo8888. 888 888 888 888 888 888 888 888
+# 888 `88b. d8( 888 888 888 o. )88b .8' `888. 888 888 888 888 888 888 888 888
+# o888o o888o `Y888""8o o888o o888o 8""888P' o88o o8888o `Y8bod88P" o888o o888o o888o o888o o888o o888o
+
+# RailsAdmin config file. Generated on <%= DateTime.now.to_s(:long) %>
+# See github.com/sferik/rails_admin for more informations
+
+RailsAdmin.config do |config|
+
+ config.current_user_method { current_<%= @model_name %> } # auto-generated
+
+ # Set the admin name here (optional second array element will appear in a beautiful RailsAdmin red ©)
+ config.main_app_name = ['<%= Rails.application.engine_name.titleize.chomp(' Application') %>', 'Admin']
+ # or for a dynamic name:
+ # config.main_app_name = Proc.new { |controller| [Rails.application.engine_name.titleize, controller.params['action'].titleize] }
+
+ # ==> Authentication (before_filter)
+ # This is run inside the controller instance so you can setup any authentication you need to.
+ # By default, the authentication will run via warden if available.
+ # and will run on the default user scope.
+ # If you use devise, this will authenticate the same as authenticate_user!
+ # Example Devise admin
+ # RailsAdmin.config do |config|
+ # config.authenticate_with do
+ # authenticate_admin!
+ # end
+ # end
+ # Example Custom Warden
+ # RailsAdmin.config do |config|
+ # config.authenticate_with do
+ # warden.authenticate! :scope => :paranoid
+ # end
+ # end
+
+ # ==> Authorization
+ # Use cancan https://github.com/ryanb/cancan for authorization:
+ # config.authorize_with :cancan
+
+ # Or use simple custom authorization rule:
+ # config.authorize_with do
+ # redirect_to root_path unless warden.user.is_admin?
+ # end
+
+ # Use a specific role for ActiveModel's :attr_acessible :attr_protected
+ # Default is :default
+ # current_user is accessible in the block if you want to make it user specific.
+ # config.attr_accessible_role { :default }
+
+ # ==> Global show view settings
+ # Display empty fields in show views
+ # config.compact_show_view = false
+
+ # ==> Global list view settings
+ # Number of default rows per-page:
+ # config.default_items_per_page = 50
+
+ # ==> Included models
+ # Add all excluded models here:
+ # config.excluded_models << [<%= RailsAdmin::AbstractModel.all_models.map(&:name).join(', ') %>]
+
+ # Add models here if you want to go 'whitelist mode':
+ # config.included_models << [<%= RailsAdmin::AbstractModel.all_models.map(&:name).join(', ') %>]
+
+ # Application wide tried label methods for models' instances
+ # config.label_methods << [:description] # Default is [:name, :title]
+
+ # ==> Global models configuration
+ # config.models do
+ # # Configuration here will affect all included models in all scopes, handle with care!
+ #
+ # list do
+ # # Configuration here will affect all included models in list sections (same for show, export, edit, update, create)
+ #
+ # fields :name, :other_name do
+ # # Configuration here will affect all fields named [:name, :other_name], in the list section, for all included models
+ # end
+ #
+ # fields_of_type :date do
+ # # Configuration here will affect all date fields, in the list section, for all included models. See README for a comprehensive type list.
+ # end
+ # end
+ # end
+ #
+ # ==> Model specific configuration
+ # Keep in mind that *all* configuration blocks are optional.
+ # RailsAdmin will try his best to provide the best defaults for each section, for each field!
+ # Try to override as few things as possible, in the most generic way. Try to avoid setting labels for models and attributes, use ActiveRecord I18n API instead.
+ # Less code is better code!
+ # config.model MyModel do
+ # # Here goes your cross-section field configuration for ModelName.
+ # object_label_method :name # Name of the method called for pretty printing an *instance* of ModelName
+ # label 'My model' # Name of ModelName (smartly defaults to ActiveRecord's I18n API)
+ # label_plural 'My models' # Same, plural
+ # weight -1 # Navigation priority. Bigger is higher.
+ # parent OtherModel # Set parent model for navigation. MyModel will be nested below. OtherModel will be on first position of the dropdown
+ # navigation_label # Sets dropdown entry's name in navigation. Only for parents!
+ # # Section specific configuration:
+ # list do
+ # filters [:id, :name] # Array of field names which filters should be shown by default in the table header
+ # items_per_page 100 # Override default_items_per_page
+ # sort_by :id # Sort column (default is primary key)
+ # sort_reverse true # Sort direction (default is true for primary key, last created first)
+ # # Here goes the fields configuration for the list view
+ # end
+ # show do
+ # # Here goes the fields configuration for the show view
+ # end
+ # export do
+ # # Here goes the fields configuration for the export view (CSV, yaml, XML)
+ # end
+ # edit do
+ # # Here goes the fields configuration for the edit view (for create and update view)
+ # end
+ # create do
+ # # Here goes the fields configuration for the create view, overriding edit section settings
+ # end
+ # update do
+ # # Here goes the fields configuration for the update view, overriding edit section settings
+ # end
+ # end
+
+# fields configuration is described in the Readme, if you have other question, ask us on the mailing-list!
+
+# ==> Your models configuration, to help you get started!
+<% RailsAdmin::AbstractModel.all.map do |abstract_model| -%>
+
+# All fields marked as 'hidden' won't be shown anywhere in the rails_admin unless you mark them as visible.
+# There can be different reasons for that:
+# - belongs_to _id and _type (polymorphic) columns are hidden in favor of their associations
+# - associations are hidden if they have no matchable model found (model not included or non-existant)
+# - they are part of a bigger plan in a plugin (Devise/Paperclip) and hidden by contract
+# Some fields may be hidden depending on the section, if they aren't deemed suitable for display or edition on that section
+# - non-editable columns (:id, :created_at, ..) in edit sections
+# - has_many/has_one associations in list section (hidden by default for performance reasons)
+# Fields may also be marked as read_only (and thus not editable) if they are not mass-assignable by current_user
+
+ # config.model <%= abstract_model.model.model_name %> do
+ # # Found associations:
+<% RailsAdmin.config(abstract_model).export.fields.select{|f| f.association?}.each do |field| -%>
+ # field <%= field.name.inspect %>, <%= field.type.inspect %><%= " # Hidden" unless field.visible? %>
+<% end -%>
+ # # Found columns:
+<% RailsAdmin.config(abstract_model).export.fields.select{|f| !f.association?}.each do |field| -%>
+ # field <%= field.name.inspect %>, <%= field.type.inspect %><%= " # Hidden" unless field.visible? %>
+<% end -%>
+ # # Sections:
+ # list do; end
+ # export do; end
+ # show do; end
+ # edit do; end
+ # create do; end
+ # update do; end
+ # end
+<% end %>
+end
+
+# You made it this far? You're looking for something that doesn't exist! Add it to RailsAdmin and send us a Pull Request!
View
60 lib/generators/rails_admin/utils.rb
@@ -1,30 +1,30 @@
-module RailsAdmin
- module Generators
- module Utils
- module InstanceMethods
- def display(output, color = :green)
- say(" - #{output}", color)
- end
-
- def ask_for(wording, default_value = nil, override_if_present_value = nil)
- override_if_present_value.present? ?
- display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value :
- ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
- end
- end
-
- module ClassMethods
- def next_migration_number(dirname)
- if ActiveRecord::Base.timestamped_migrations
- migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
- migration_number += 1
- migration_number.to_s
- else
- "%.3d" % (current_migration_number(dirname) + 1)
- end
- end
- end
- end
- end
-end
-
+module RailsAdmin
+ module Generators
+ module Utils
+ module InstanceMethods
+ def display(output, color = :green)
+ say(" - #{output}", color)
+ end
+
+ def ask_for(wording, default_value = nil, override_if_present_value = nil)
+ override_if_present_value.present? ?
+ display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value :
+ ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
+ end
+ end
+
+ module ClassMethods
+ def next_migration_number(dirname)
+ if ActiveRecord::Base.timestamped_migrations
+ migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
+ migration_number += 1
+ migration_number.to_s
+ else
+ "%.3d" % (current_migration_number(dirname) + 1)
+ end
+ end
+ end
+ end
+ end
+end
+
View
116 lib/rails_admin.rb
@@ -1,58 +1,58 @@
-require 'rails_admin/engine'
-require 'rails_admin/abstract_model'
-require 'rails_admin/abstract_history'
-require 'rails_admin/config'
-require 'rails_admin/extension'
-require 'rails_admin/extensions/cancan'
-require 'rails_admin/support/csv_converter'
-require 'rails_admin/support/core_extensions'
-
-module RailsAdmin
- def self.authenticate_with(&block)
- ActiveSupport::Deprecation.warn("'#{self.name}.authenticate_with { }' is deprecated, use 'RailsAdmin.config{|c| c.authenticate_with }' instead", caller)
- self.config {|c| c.authenticate_with(&block) }
- end
-
- def self.authorize_with(*args, &block)
- ActiveSupport::Deprecation.warn("'#{self.name}.authorize_with { }' is deprecated, use 'RailsAdmin.config{|c| c.authorize_with }' instead", caller)
- self.config {|c| c.authorize_with(*args, &block) }
- end
-
- def self.current_user_method(&block)
- ActiveSupport::Deprecation.warn("'#{self.name}.current_user_method { }' is deprecated, use 'RailsAdmin.config{|c| c.current_user_method }' instead", caller)
- self.config {|c| c.current_user_method(&block) }
- end
-
- def self.configure_with(extension, &block)
- ActiveSupport::Deprecation.warn("'#{self.name}.configure_with { }' is deprecated, use 'RailsAdmin.config{|c| c.configure_with }' instead", caller)
- self.config {|c| c.configure_with(extension, &block) }
- end
-
- # Setup RailsAdmin
- #
- # Given the first argument is a model class, a model class name
- # or an abstract model object proxies to model configuration method.
- #
- # If only a block is passed it is stored to initializer stack to be evaluated
- # on first request in production mode and on each request in development. If
- # initialization has already occured (in other words RailsAdmin.setup has
- # been called) the block will be added to stack and evaluated at once.
- #
- # Otherwise returns RailsAdmin::Config class.
- #
- # @see RailsAdmin::Config
- def self.config(entity = nil, &block)
- if entity
- RailsAdmin::Config.model(entity, &block)
- elsif block_given?
- block.call(RailsAdmin::Config)
- else
- RailsAdmin::Config
- end
- end
-
- # Reset RailsAdmin configuration to defaults
- def self.reset
- RailsAdmin::Config.reset
- end
-end
+require 'rails_admin/engine'
+require 'rails_admin/abstract_model'
+require 'rails_admin/abstract_history'
+require 'rails_admin/config'
+require 'rails_admin/extension'
+require 'rails_admin/extensions/cancan'
+require 'rails_admin/support/csv_converter'
+require 'rails_admin/support/core_extensions'
+
+module RailsAdmin
+ def self.authenticate_with(&block)
+ ActiveSupport::Deprecation.warn("'#{self.name}.authenticate_with { }' is deprecated, use 'RailsAdmin.config{|c| c.authenticate_with }' instead", caller)
+ self.config {|c| c.authenticate_with(&block) }
+ end
+
+ def self.authorize_with(*args, &block)
+ ActiveSupport::Deprecation.warn("'#{self.name}.authorize_with { }' is deprecated, use 'RailsAdmin.config{|c| c.authorize_with }' instead", caller)
+ self.config {|c| c.authorize_with(*args, &block) }
+ end
+
+ def self.current_user_method(&block)
+ ActiveSupport::Deprecation.warn("'#{self.name}.current_user_method { }' is deprecated, use 'RailsAdmin.config{|c| c.current_user_method }' instead", caller)
+ self.config {|c| c.current_user_method(&block) }
+ end
+
+ def self.configure_with(extension, &block)
+ ActiveSupport::Deprecation.warn("'#{self.name}.configure_with { }' is deprecated, use 'RailsAdmin.config{|c| c.configure_with }' instead", caller)
+ self.config {|c| c.configure_with(extension, &block) }
+ end
+
+ # Setup RailsAdmin
+ #
+ # Given the first argument is a model class, a model class name
+ # or an abstract model object proxies to model configuration method.
+ #
+ # If only a block is passed it is stored to initializer stack to be evaluated
+ # on first request in production mode and on each request in development. If
+ # initialization has already occured (in other words RailsAdmin.setup has
+ # been called) the block will be added to stack and evaluated at once.
+ #
+ # Otherwise returns RailsAdmin::Config class.
+ #
+ # @see RailsAdmin::Config
+ def self.config(entity = nil, &block)
+ if entity
+ RailsAdmin::Config.model(entity, &block)
+ elsif block_given? && ENV['SKIP_RAILS_ADMIN_INITIALIZER'] != "true"
+ block.call(RailsAdmin::Config)
+ else
+ RailsAdmin::Config
+ end
+ end
+
+ # Reset RailsAdmin configuration to defaults
+ def self.reset
+ RailsAdmin::Config.reset
+ end
+end
View
548 lib/rails_admin/config/fields/base.rb
@@ -1,274 +1,274 @@
-require 'active_support/core_ext/string/inflections'
-require 'rails_admin/config/base'
-require 'rails_admin/config/hideable'
-require 'rails_admin/config/has_groups'
-require 'rails_admin/config/fields'
-require 'rails_admin/config/fields/groupable'
-require 'rails_admin/config/fields/association'
-
-module RailsAdmin
- module Config
- module Fields
- class Base < RailsAdmin::Config::Base
- attr_reader :name, :properties
- attr_accessor :defined, :order
-
- def self.inherited(klass)
- klass.instance_variable_set("@css_class", klass.name.to_s.demodulize.camelcase(:lower))
- klass.instance_variable_set("@view_helper", :text_field)
- end
-
- include RailsAdmin::Config::Hideable
-
- def initialize(parent, name, properties)
- super(parent)
-
- @defined = false
- @name = name
- @order = 0
- @properties = properties
-
- # If parent is able to group fields the field should be aware of it
- if parent.kind_of?(RailsAdmin::Config::HasGroups)
- extend RailsAdmin::Config::Fields::Groupable
- end
- end
-
- register_instance_option(:css_class) do
- self.class.instance_variable_get("@css_class")
- end
-
- def column_css_class(*args, &block)
- if !args[0].nil? || block
- @css_class = args[0].nil? ? block : args[0]
- else
- css_class
- end
- end
-
- def virtual?
- properties.blank?
- end
-
- register_instance_option(:column_width) do
- self.class.instance_variable_get("@column_width")
- end
-
- register_instance_option(:read_only) do
- role = bindings[:view].controller.send(:_attr_accessible_role)
- klass = bindings[:object].class
- whitelist = klass.accessible_attributes(role).map(&:to_s)
- blacklist = klass.protected_attributes(role).map(&:to_s)
- self.method_name.to_s.in?(blacklist) || (whitelist.any? ? !self.method_name.to_s.in?(whitelist) : false)
- end
-
- register_instance_option(:truncated?) do
- ActiveSupport::Deprecation.warn("'#{self.name}.truncated?' is deprecated, use '#{self.name}.pretty_value' instead", caller)
- end
-
- register_instance_option(:sortable) do
- !virtual?
- end
-
- register_instance_option(:searchable) do
- !virtual?
- end
-
- register_instance_option(:queryable?) do
- !!searchable
- end
-
- register_instance_option(:filterable?) do
- !!searchable
- end
-
- register_instance_option(:search_operator) do
- @search_operator ||= RailsAdmin::Config.default_search_operator
- end
-
- # serials and dates are reversed in list, which is more natural (last modified items first).
- register_instance_option(:sort_reverse?) do
- false
- end
-
- # list of columns I should search for that field [{ :column => 'table_name.column', :type => field.type }, {..}]
- register_instance_option(:searchable_columns) do
- @searchable_columns ||= case self.searchable
- when true
- [{ :column => "#{self.abstract_model.model.table_name}.#{self.name}", :type => self.type }]
- when false
- []
- when :all # valid only for associations
- self.associated_model_config.list.fields.map { |f| { :column => "#{self.associated_model_config.abstract_model.model.table_name}.#{f.name}", :type => f.type } }
- else
- [self.searchable].flatten.map do |f|
- if f.is_a?(String) && f.include?('.') # "table_name.attribute"
- @table_name, column_name = f.split '.'
- f = column_name.to_sym
- end
-
- field_name = f.is_a?(Hash) ? f.values.first : f
-
- abstract_model = if f.is_a?(Hash) && (f.keys.first.is_a?(Class) || f.keys.first.is_a?(String)) # { Model => :attribute } || { "Model" => :attribute }
- AbstractModel.new(f.keys.first)
- elsif f.is_a?(Hash) # { :table_name => :attribute }
- @table_name = f.keys.first.to_s
- (self.association? ? self.associated_model_config.abstract_model : self.abstract_model)
- else # :attribute
- (self.association? ? self.associated_model_config.abstract_model : self.abstract_model)
- end
-
- property = abstract_model.properties.find{ |p| p[:name] == field_name }
- raise ":#{field_name} attribute not found/not accessible on table :#{abstract_model.model.table_name}. \nPlease check '#{self.abstract_model.pretty_name}' configuration for :#{self.name} attribute." unless property
- { :column => "#{@table_name || abstract_model.model.table_name}.#{property[:name]}", :type => property[:type] }
- end
- end
- end
-
- register_instance_option(:formatted_value) do
- value.to_s
- end
-
- # output for pretty printing (show, list)
- register_instance_option(:pretty_value) do
- formatted_value
- end
-
- # output for printing in export view (developers beware: no bindings[:view] and no data!)
- register_instance_option(:export_value) do
- pretty_value
- end
-
-
- # Accessor for field's help text displayed below input field.
- register_instance_option(:help) do
- @help ||= (required? ? I18n.translate("admin.new.required") : I18n.translate("admin.new.optional")) + '. '
- end
-
- register_instance_option(:html_attributes) do
- {
- :class => css_class
- }
- end
-
- # Accessor for field's label.
- #
- # @see RailsAdmin::AbstractModel.properties
- register_instance_option(:label) do
- @label ||= abstract_model.model.human_attribute_name name
- end
-
- # Accessor for field's maximum length.
- #
- # @see RailsAdmin::AbstractModel.properties
- register_instance_option(:length) do
- @length ||= properties && properties[:length]
- end
-
- register_instance_option(:partial) do
- :form_field
- end
-
- register_deprecated_instance_option(:show_partial, :partial) # deprecated on 2011-07-15
- register_deprecated_instance_option(:edit_partial, :partial) # deprecated on 2011-07-15
- register_deprecated_instance_option(:create_partial, :partial) # deprecated on 2011-07-15
- register_deprecated_instance_option(:update_partial, :partial) # deprecated on 2011-07-15
-
- register_instance_option(:render) do
- bindings[:view].render :partial => partial.to_s, :locals => {:field => self, :form => bindings[:form] }
- end
-
- # Accessor for whether this is field is mandatory.
- #
- # @see RailsAdmin::AbstractModel.properties
- register_instance_option(:required?) do
- @required ||= !!abstract_model.model.validators_on(name).find do |v|
- v.is_a?(ActiveModel::Validations::PresenceValidator) || !v.options[:allow_nil]
- end
- end
-
- # Accessor for whether this is a serial field (aka. primary key, identifier).
- #
- # @see RailsAdmin::AbstractModel.properties
- register_instance_option(:serial?) do
- properties && properties[:serial?]
- end
-
- register_instance_option(:view_helper) do
- @view_helper ||= self.class.instance_variable_get("@view_helper")
- end
-
- # Is this an association
- def association?
- kind_of?(RailsAdmin::Config::Fields::Association)
- end
-
- # Reader for validation errors of the bound object
- def errors
- bindings[:object].errors[name]
- end
-
- # Reader whether the bound object has validation errors
- def has_errors?
- # TODO DEPRECATE, USELESS
- errors.present?
- end
-
- # Reader whether field is optional.
- #
- # @see RailsAdmin::Config::Fields::Base.register_instance_option(:required?)
- def optional?
- not required
- end
-
- # Inverse accessor whether this field is required.
- #
- # @see RailsAdmin::Config::Fields::Base.register_instance_option(:required?)
- def optional(state = nil, &block)
- if !state.nil? || block
- required state.nil? ? proc { false == (instance_eval &block) } : false == state
- else
- optional?
- end
- end
-
- # Writer to make field optional.
- #
- # @see RailsAdmin::Config::Fields::Base.optional
- def optional=(state)
- optional(state)
- end
-
- # Reader for field's type
- def type
- @type ||= self.class.name.to_s.demodulize.underscore.to_sym
- end
-
- # Reader for field's value
- def value
- bindings[:object].safe_send(name)
- end
-
- # Reader for field's name
- def dom_name
- @dom_name ||= "#{bindings[:form].object_name}#{(index = bindings[:form].options[:index]) && "[#{index}]"}[#{method_name}]"
- end
-
- # Reader for field's id
- def dom_id
- @dom_id ||= [
- bindings[:form].object_name,
- bindings[:form].options[:index],
- method_name
- ].reject(&:blank?).join('_')
- end
-
- def method_name
- name
- end
-
-
- end
- end
- end
-end
+require 'active_support/core_ext/string/inflections'
+require 'rails_admin/config/base'
+require 'rails_admin/config/hideable'
+require 'rails_admin/config/has_groups'
+require 'rails_admin/config/fields'
+require 'rails_admin/config/fields/groupable'
+require 'rails_admin/config/fields/association'
+
+module RailsAdmin
+ module Config
+ module Fields
+ class Base < RailsAdmin::Config::Base
+ attr_reader :name, :properties
+ attr_accessor :defined, :order
+
+ def self.inherited(klass)
+ klass.instance_variable_set("@css_class", klass.name.to_s.demodulize.camelcase(:lower))
+ klass.instance_variable_set("@view_helper", :text_field)
+ end
+
+ include RailsAdmin::Config::Hideable
+
+ def initialize(parent, name, properties)
+ super(parent)
+
+ @defined = false
+ @name = name
+ @order = 0
+ @properties = properties
+
+ # If parent is able to group fields the field should be aware of it
+ if parent.kind_of?(RailsAdmin::Config::HasGroups)
+ extend RailsAdmin::Config::Fields::Groupable
+ end
+ end
+
+ register_instance_option(:css_class) do
+ self.class.instance_variable_get("@css_class")
+ end
+
+ def column_css_class(*args, &block)
+ if !args[0].nil? || block
+ @css_class = args[0].nil? ? block : args[0]
+ else
+ css_class
+ end
+ end
+
+ def virtual?
+ properties.blank?
+ end
+
+ register_instance_option(:column_width) do
+ self.class.instance_variable_get("@column_width")
+ end
+
+ register_instance_option(:read_only) do
+ role = bindings[:view].controller.send(:_attr_accessible_role)
+ klass = bindings[:object].class
+ whitelist = klass.accessible_attributes(role).map(&:to_s)
+ blacklist = klass.protected_attributes(role).map(&:to_s)
+ self.method_name.to_s.in?(blacklist) || (whitelist.any? ? !self.method_name.to_s.in?(whitelist) : false)
+ end
+
+ register_instance_option(:truncated?) do
+ ActiveSupport::Deprecation.warn("'#{self.name}.truncated?' is deprecated, use '#{self.name}.pretty_value' instead", caller)
+ end
+
+ register_instance_option(:sortable) do
+ !virtual?
+ end
+
+ register_instance_option(:searchable) do
+ !virtual?
+ end
+
+ register_instance_option(:queryable?) do
+ !!searchable
+ end
+
+ register_instance_option(:filterable?) do
+ !!searchable
+ end
+
+ register_instance_option(:search_operator) do
+ @search_operator ||= RailsAdmin::Config.default_search_operator
+ end
+
+ # serials and dates are reversed in list, which is more natural (last modified items first).
+ register_instance_option(:sort_reverse?) do
+ false
+ end
+
+ # list of columns I should search for that field [{ :column => 'table_name.column', :type => field.type }, {..}]
+ register_instance_option(:searchable_columns) do
+ @searchable_columns ||= case self.searchable
+ when true
+ [{ :column => "#{self.abstract_model.model.table_name}.#{self.name}", :type => self.type }]
+ when false
+ []
+ when :all # valid only for associations
+ self.associated_model_config.list.fields.map { |f| { :column => "#{self.associated_model_config.abstract_model.model.table_name}.#{f.name}", :type => f.type } }
+ else
+ [self.searchable].flatten.map do |f|
+ if f.is_a?(String) && f.include?('.') # "table_name.attribute"
+ @table_name, column_name = f.split '.'
+ f = column_name.to_sym
+ end
+
+ field_name = f.is_a?(Hash) ? f.values.first : f
+
+ abstract_model = if f.is_a?(Hash) && (f.keys.first.is_a?(Class) || f.keys.first.is_a?(String)) # { Model => :attribute } || { "Model" => :attribute }
+ AbstractModel.new(f.keys.first)
+ elsif f.is_a?(Hash) # { :table_name => :attribute }
+ @table_name = f.keys.first.to_s
+ (self.association? ? self.associated_model_config.abstract_model : self.abstract_model)
+ else # :attribute
+ (self.association? ? self.associated_model_config.abstract_model : self.abstract_model)
+ end
+
+ property = abstract_model.properties.find{ |p| p[:name] == field_name }
+ raise ":#{field_name} attribute not found/not accessible on table :#{abstract_model.model.table_name}. \nPlease check '#{self.abstract_model.pretty_name}' configuration for :#{self.name} attribute." unless property
+ { :column => "#{@table_name || abstract_model.model.table_name}.#{property[:name]}", :type => property[:type] }
+ end
+ end
+ end
+
+ register_instance_option(:formatted_value) do
+ value.to_s
+ end
+
+ # output for pretty printing (show, list)
+ register_instance_option(:pretty_value) do
+ formatted_value
+ end
+
+ # output for printing in export view (developers beware: no bindings[:view] and no data!)
+ register_instance_option(:export_value) do
+ pretty_value
+ end
+
+
+ # Accessor for field's help text displayed below input field.
+ register_instance_option(:help) do
+ @help ||= (required? ? I18n.translate("admin.new.required") : I18n.translate("admin.new.optional")) + '. '
+ end
+
+ register_instance_option(:html_attributes) do
+ {
+ :class => css_class
+ }
+ end
+
+ # Accessor for field's label.
+ #
+ # @see RailsAdmin::AbstractModel.properties
+ register_instance_option(:label) do
+ @label ||= abstract_model.model.human_attribute_name name
+ end
+
+ # Accessor for field's maximum length.
+ #
+ # @see RailsAdmin::AbstractModel.properties
+ register_instance_option(:length) do
+ @length ||= properties && properties[:length]
+ end
+
+ register_instance_option(:partial) do
+ :form_field
+ end
+
+ register_deprecated_instance_option(:show_partial, :partial) # deprecated on 2011-07-15
+ register_deprecated_instance_option(:edit_partial, :partial) # deprecated on 2011-07-15
+ register_deprecated_instance_option(:create_partial, :partial) # deprecated on 2011-07-15
+ register_deprecated_instance_option(:update_partial, :partial) # deprecated on 2011-07-15
+
+ register_instance_option(:render) do
+ bindings[:view].render :partial => partial.to_s, :locals => {:field => self, :form => bindings[:form] }
+ end
+
+ # Accessor for whether this is field is mandatory.
+ #
+ # @see RailsAdmin::AbstractModel.properties
+ register_instance_option(:required?) do
+ @required ||= !!abstract_model.model.validators_on(name).find do |v|
+ v.is_a?(ActiveModel::Validations::PresenceValidator) || !v.options[:allow_nil]
+ end
+ end
+
+ # Accessor for whether this is a serial field (aka. primary key, identifier).
+ #
+ # @see RailsAdmin::AbstractModel.properties
+ register_instance_option(:serial?) do
+ properties && properties[:serial?]
+ end
+
+ register_instance_option(:view_helper) do
+ @view_helper ||= self.class.instance_variable_get("@view_helper")
+ end
+
+ # Is this an association
+ def association?
+ kind_of?(RailsAdmin::Config::Fields::Association)
+ end
+
+ # Reader for validation errors of the bound object
+ def errors
+ bindings[:object].errors[name]
+ end
+
+ # Reader whether the bound object has validation errors
+ def has_errors?
+ # TODO DEPRECATE, USELESS
+ errors.present?
+ end
+
+ # Reader whether field is optional.
+ #
+ # @see RailsAdmin::Config::Fields::Base.register_instance_option(:required?)
+ def optional?
+ not required
+ end
+
+ # Inverse accessor whether this field is required.
+ #
+ # @see RailsAdmin::Config::Fields::Base.register_instance_option(:required?)
+ def optional(state = nil, &block)
+ if !state.nil? || block
+ required state.nil? ? proc { false == (instance_eval &block) } : false == state
+ else
+ optional?
+ end
+ end
+
+ # Writer to make field optional.
+ #
+ # @see RailsAdmin::Config::Fields::Base.optional
+ def optional=(state)
+ optional(state)
+ end
+
+ # Reader for field's type
+ def type
+ @type ||= self.class.name.to_s.demodulize.underscore.to_sym
+ end
+
+ # Reader for field's value
+ def value
+ bindings[:object].safe_send(name)
+ end
+
+ # Reader for field's name
+ def dom_name
+ @dom_name ||= "#{bindings[:form].object_name}#{(index = bindings[:form].options[:index]) && "[#{index}]"}[#{method_name}]"
+ end
+
+ # Reader for field's id
+ def dom_id
+ @dom_id ||= [
+ bindings[:form].object_name,
+ bindings[:form].options[:index],
+ method_name
+ ].reject(&:blank?).join('_')
+ end
+
+ def method_name
+ name
+ end
+
+
+ end
+ end
+ end
+end
View
4 lib/tasks/skip_rails_admin_initializer.rake
@@ -0,0 +1,4 @@
+task :environment => :disable_rails_admin_initializer
+task :disable_rails_admin_initializer do
+ ENV['SKIP_RAILS_ADMIN_INITIALIZER'] = 'true' if ENV['SKIP_RAILS_ADMIN_INITIALIZER'].nil?
+end
View
17 lib/tasks/uninstall.rake
@@ -1,8 +1,9 @@
-require File.expand_path('../../rails_admin/tasks/uninstall', __FILE__)
-
-namespace :rails_admin do
- desc "Uninstall rails_admin"
- task :uninstall do
- RailsAdmin::Tasks::Uninstall.run
- end
-end
+require File.expand_path('../../rails_admin/tasks/uninstall', __FILE__)
+
+namespace :rails_admin do
+ desc "Uninstall rails_admin"
+ task :uninstall do
+ RailsAdmin::Tasks::Uninstall.run
+ end
+end
+
View
90 spec/dummy_app/config/application.rb
@@ -1,45 +1,45 @@
-require File.expand_path('../boot', __FILE__)
-
-require 'rails/all'
-require 'devise'
-require 'paperclip'
-
-# If you have a Gemfile, require the default gems, the ones in the
-# current environment and also include :assets gems if in development
-# or test environments.
-Bundler.require *Rails.groups(:assets) if defined?(Bundler)
-
-module DummyApp
- class Application < Rails::Application
- # Settings in config/environments/* take precedence over those specified here.
- # Application configuration should go into files in config/initializers
- # -- all .rb files in that directory are automatically loaded.
-
- # Custom directories with classes and modules you want to be autoloadable.
- # config.autoload_paths += %W(#{config.root}/extras)
-
- # Only load the plugins named here, in the order given (default is alphabetical).
- # :all can be used as a placeholder for all plugins not explicitly named.
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
-
- # Activate observers that should always be running.
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
-
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
- # config.time_zone = 'Central Time (US & Canada)'
-
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- config.i18n.load_path += Dir[Rails.root.join('app', 'locales', '*.{rb,yml}').to_s]
- # config.i18n.default_locale = :de
-
- # Configure the default encoding used in templates for Ruby 1.9.
- config.encoding = "utf-8"
-
- # Configure sensitive parameters which will be filtered from the log file.
- config.filter_parameters += [:password]
-
- # Enable the asset pipeline
- config.assets.enabled = true
- end
-end
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+require 'devise'
+require 'paperclip'
+
+# If you have a Gemfile, require the default gems, the ones in the
+# current environment and also include :assets gems if in development
+# or test environments.
+Bundler.require *Rails.groups(:assets) if defined?(Bundler)
+
+module DummyApp
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ config.i18n.load_path += Dir[Rails.root.join('app', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+
+ # Enable the asset pipeline
+ config.assets.enabled = true
+ end
+end
View
54 spec/dummy_app/config/environments/development.rb
@@ -1,27 +1,27 @@
-DummyApp::Application.configure do
- # Settings specified here will take precedence over those in config/application.rb
-
- # In the development environment your application's code is reloaded on
- # every request. This slows down response time but is perfect for development
- # since you don't have to restart the web server when you make code changes.
- config.cache_classes = false
-
- # Log error messages when you accidentally call methods on nil.
- config.whiny_nils = true
-
- # Show full error reports and disable caching
- config.consider_all_requests_local = true
- config.action_controller.perform_caching = false
-
- # Don't care if the mailer can't send
- config.action_mailer.raise_delivery_errors = false
-
- # Print deprecation notices to the Rails logger
- config.active_support.deprecation = :log
-
- # Only use best-standards-support built into browsers
- config.action_dispatch.best_standards_support = :builtin
-
- # Do not compress assets
- config.assets.compress = false
-end
+DummyApp::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+
+ # Do not compress as