spec/dummy_app/tmp/cache/assets/test/sprockets/b8a8c2faf730407b004ec269c26473d7 in basepack-1.0.0.pre.0 vs spec/dummy_app/tmp/cache/assets/test/sprockets/b8a8c2faf730407b004ec269c26473d7 in basepack-1.0.0
- old
+ new
@@ -1,8 +1,8 @@
{I"
class:ETI"ProcessedAsset; FI"logical_path; TI"basepack/forms.js; FI"
pathname; TI"O/home/lukas/projects/basepack/app/assets/javascripts/basepack/forms.coffee; FI"content_type; TI"application/javascript; TI"
-mtime; Tl+FˆSI"length; Ti•LI"digest; TI"%ecb3babdad40438d108db60657a1ce4f; FI"source; TI"•L(function() {
+mtime; Tl+ÝlºSI"length; TiøXI"digest; TI"%45af775fc4d43086dc0d47c720e49db5; FI"source; TI"øX(function() {
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
$.fn.findExtended = function(selector) {
if (_.str.startsWith(selector, "parent=")) {
@@ -495,14 +495,102 @@
})(Basepack.Form.Plugin);
/**
+ * @name DynamicRemoteField automatically re-renders field(s) depending on the change of other field
+
+ * @description takes all elements with data-dynamic-remote-field which identifies select on which value change
+ this element (with data-dynamic-remote-field attribute) is rerendered with values of remote call
+
+ NOTE: parameters are brought from html data attributes
+ * @param {String} data-dynamic-remote-field identification of the field which changes are watched
+ * @param {String} dependant-param additional parameter that is send to remote
+ * @param {Object} options contains url adress (remote_sourece key) to which ajax request is made to obtain data (html template)
+
+ * @returns {html} returns html template
+
+ * @example on the field gift_packages following html data attribues are added
+
+ * this is haml
+ .accordion{:data=>{
+ "dynamic-remote-field"=>"#subscription_order_order_template_id",
+ "dependant-param"=>"subscription_order[order_template_id]",
+ "options"=>"{\"remote_source\":\"/subscription_orders/gift_packages_partial\"}"}
+ }
+ %div.content Custom content
+
+ * this is the order_template field definition in meta data
+ field :order_template do
+ help ''
+ param = "f[main_magazine_magazine_group_id_eq]"
+ options_source_params do
+ { param => bindings[:object].magazine_group.try(:id) || -1,
+ 'f[offerable]' => true,
+ 'f[s]' => 'price asc'
+ }
+ end
+ html_attributes do
+ {
+ data: {
+ "dependant-filteringselect" => "#subscription_order_magazine_group_id",
+ "dependant-param" => param,
+ :placeholder => "Vyberte, prosÃm"
+ }
+ }
+ end
+ end
+ */
+
+ Basepack.Form.Plugins.DynamicRemoteField = (function(_super) {
+ __extends(DynamicRemoteField, _super);
+
+ function DynamicRemoteField() {
+ return DynamicRemoteField.__super__.constructor.apply(this, arguments);
+ }
+
+ DynamicRemoteField.prototype.bind = function() {
+ var plugin;
+ plugin = this;
+ return this.form.find('[data-dynamic-remote-field]').each(function() {
+ var dependsOn, group, that;
+ that = $(this);
+ group = that.parents('.control-group:first');
+ dependsOn = that.findExtended(that.data('dynamic-remote-field'));
+ return dependsOn.on('change', function(e) {
+ var options;
+ options = _.clone(that.data('options'));
+ if (e.val !== "" && (e.val != null)) {
+ options.remote_source_params = _.clone(options.remote_source_params) || {};
+ options.remote_source_params[that.data('dependantParam')] = e.val;
+ return plugin.ajax(options, group);
+ }
+ });
+ });
+ };
+
+ DynamicRemoteField.prototype.ajax = function(options, group) {
+ return $.ajax(options.remote_source, {
+ data: $.extend({}, options.remote_source_params),
+ dataType: "html"
+ }).done(function(data) {
+ return group.html(data);
+ }).fail(function() {
+ return group.html('<div class="alert alert-error">Could not load data from server. We are sorry.</div>');
+ });
+ };
+
+ return DynamicRemoteField;
+
+ })(Basepack.Form.Plugin);
+
+
+ /**
* Dynamically show/hide fields based on other field value.
* takes all elements with data-dynamic-fields and use this data attribute as an configuration:
- @param{data-dynamic-fields} array of actions. Each action is a hash with keys:
+ @param{data-dynamic-fields} array of actions. Each action is a hash with keys:
condition - condition which should be met (Stirng: field has to equal, Array: field has to match one of item of array)
field_actions - hash. Keys are other fields on which are taken action.
* Exmaple:
[{"condition":["aaa","hide"],"field_actions":{"www":{"visible":false}}},{"condition":"xxx","field_actions":{"www":{"visible":true}}}]
@@ -596,13 +684,11 @@
function Orderable() {
return Orderable.__super__.constructor.apply(this, arguments);
}
Orderable.prototype.update_sort_order = function() {
- console.log('volam update_sort_order');
return this.form.find('.fields').each(function(idx, fields) {
- console.log('updatuji: ' + idx);
return $(fields).find('input[name$="[position]"]').val(idx + 1);
});
};
Orderable.prototype.bind = function() {
@@ -624,7 +710,7 @@
return Orderable;
})(Basepack.Form.Plugin);
}).call(this);
-; TI"dependency_digest; TI"%3e31dbc3016affdb6fb5e02c9ea03005; FI"required_paths; T[I"O/home/lukas/projects/basepack/app/assets/javascripts/basepack/forms.coffee; FI"dependency_paths; T[{I" path; TI"O/home/lukas/projects/basepack/app/assets/javascripts/basepack/forms.coffee; FI"
-mtime; TI"2014-03-07T09:50:14+01:00; TI"digest; TI"%dbd2b32d9ce9ded8d4be944194a9d2b2; FI"
_version; TI"%1005ed9f20e25fb0a0599a7017dd0e6b; F
+; TI"dependency_digest; TI"%9ab7114c99a3a3f3932502e0aae74edc; FI"required_paths; T[I"O/home/lukas/projects/basepack/app/assets/javascripts/basepack/forms.coffee; FI"dependency_paths; T[{I" path; TI"O/home/lukas/projects/basepack/app/assets/javascripts/basepack/forms.coffee; FI"
+mtime; TI"2014-07-07T11:48:13+02:00; TI"digest; TI"%e8b0415cddb7e382ae5a6506043b60b1; FI"
_version; TI"%2b66aa67c90052d553e0328c249bc9b0; F
\ No newline at end of file