spec/dummy_app/tmp/cache/assets/development/sprockets/b8a8c2faf730407b004ec269c26473d7 in basepack-1.0.0.pre.0 vs spec/dummy_app/tmp/cache/assets/development/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"%e6faa4bac25f0e538e71dc2f0d5bd121; FI"source; TI"•L(function() {
+mtime; Tl+ÝlºSI"length; TiøXI"digest; TI"%329592bb831b3c02889f674195cb673e; 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"%25d542b4129650b0c978ee604c7bb408; 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"%37774b6c71ee09b22e2ab7a43812a1ab; FI"
_version; TI"%361c512b9086418778df946c0d278f91; F
+; TI"dependency_digest; TI"%3d19fc9d9b1e1fc358a5cf0ffafa077b; 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"%09099f6833c689398a632faaea06d891; FI"
_version; TI"%361c512b9086418778df946c0d278f91; F
\ No newline at end of file