Sha256: e775a4a517dfddc3f3607b3b58b145ba215c78365d4bcdd7114a54b198d9bfd3

Contents?: true

Size: 1.89 KB

Versions: 39

Compression:

Stored size: 1.89 KB

Contents

(function ($){
  SirTrevor.BlockMixins.Formable = {
    mixinName: "Formable",
    preload: true,

    initializeFormable: function() {
      
      if (_.isUndefined(this['afterLoadData'])) {
        this['afterLoadData'] = function(data) { };
      }
    },
    
    formId: function(id) {
      return this.blockID + "_" + id;
    },

    _serializeData: function() {
      
      var data = this.$(":input,textarea,select").not(':input:radio').serializeJSON();

      this.$(':input:radio:checked').each(function(index, input) {
        var key = $(input).data('key') || input.getAttribute('name');

        if (!key.match("\\[")) {
          data[key] = $(input).val();
        }
      });

      /* Simple to start. Add conditions later */
      if (this.hasTextBlock()) {
        data.text = this.getTextBlockHTML();
        if (data.text.length > 0 && this.options.convertToMarkdown) {
          data.text = stToMarkdown(data.text, this.type);
        }
      }

      return data;
    },
    
    loadData: function(data){
      if (this.hasTextBlock()) {
        this.getTextBlock().html(SirTrevor.toHTML(data.text, this.type));
      }
      this.loadFormDataByKey(data);
      this.afterLoadData(data);
    },
    
    loadFormDataByKey: function(data) {
      this.$(':input').not('button,:input[type=hidden]').each(function(index, input) {
        var key = $(input).data('key') || input.getAttribute('name');

        if (key) {
        
          if (key.match("\\[\\]$")) {
            key = key.replace("[]", "");
          }
          
          // by wrapping it in an array, this'll "just work" for radio and checkbox fields too
          var input_data = data[key];

          if (!(input_data instanceof Array)) {
            input_data = [input_data];
          }
          $(this).val(input_data);
        }
      });
    },
  },
  

  SirTrevor.Block.prototype.availableMixins.push("formable");
})(jQuery);

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
blacklight-spotlight-0.24.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.23.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.22.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.21.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.20.3 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.20.2 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.20.1 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.20.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.19.2 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.19.1 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.19.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.18.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.17.1 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.17.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.16.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.15.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.14.2 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.14.1 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.14.0 app/assets/javascripts/spotlight/block_mixins/formable.js
blacklight-spotlight-0.13.0 app/assets/javascripts/spotlight/block_mixins/formable.js