<commit_before>module Netzke
  # == BaseJs
  # *TODO: outdated*
  # 
  # Module which provides JS-class generation functionality for the widgets ("client-side"). The generated code 
  # is evaluated once per widget class, and the results are cached in the browser. Included into Netzke::Base class.
  # 
  # == Widget javascript code
  # Here's a brief explanation on how a javascript class for a widget gets built.
  # Widget gets defined as a constructor (a function) by +js_class+ class method (see "Inside widget's contstructor").
  # +Ext.extend+ provides inheritance from an Ext class specified in +js_base_class+ class method.
  # 
  # == Inside widget's constructor
  # * Widget's constructor gets called with a parameter that is a configuration object provided by +js_config+ instance method. This configuration is specific for the instance of the widget, and, for example, contains this widget's unique id. As another example, by means of this configuration object, a grid receives the configuration array for its columns, a form - for its fields, etc. With other words, everything that may change from instance to instance of the same widget's class, goes in here.
  # * Widget executes its specific initialization code which is provided by +js_before_consttructor+ class method. 
  # For example, a grid may define its column model, a form - its fields, a tab panel - its tabs ("items").
  # * Widget calls the constructor of the inherited class (see +js_class+ class method) with a parameter that is a merge of 
  # 1) configuration parameter passed to the widget's constructor.
  module BaseJs
    def self.included(base)
      base.extend ClassMethods
    end

    #
    # Instance methods
    #

    # Config that is used for instantiating the widget in javascript
    def js_config
      res = {}
      
      # Unique id of the widget
      res.merge!(:id => global_id)
  
      # Recursively include configs of all non-late aggregatees, so that the widget can instantiate them
      # in javascript immediately.
      non_late_aggregatees.each_pair do |aggr_name, aggr_config|
        aggr_instance = aggregatee_instance(aggr_name.to_sym)
        aggr_instance.before_load
        res["#{aggr_name}_config".to_sym] = aggr_instance.js_config
      end
  
      # Api (besides the default "load_aggregatee_with_cache" - JavaScript side already knows about it)
      api_points = self.class.api_points.reject{ |p| p == :load_aggregatee_with_cache }
      res.merge!(:netzke_api => api_points) unless api_points.empty?
  
      # Widget class name. Needed for dynamic instantiation in javascript.
      # res.merge!(:widget_class_name => short_widget_class_name)
      res.merge!(:scoped_class_name => self.class.js_scoped_class_name)
      
      # Actions, toolbars and menus
      # tools   && res.merge!(:tools   => tools)
      actions && res.merge!(:actions => actions)
      menu    && res.merge!(:menu    => menu)

      # Inform the JavaScript side if persistent_config is enabled
      res[:persistent_config] = persistent_config_enabled?

      # Merge with all config options passed as hash to config[:ext_config]
      res.merge!(ext_config)

      res
    end
  
    # All the JS-code required by this instance of the widget to be instantiated in the browser.
    # It includes the JS-class for the widget itself, as well as JS-classes for all widgets' (non-late) aggregatees.
    def js_missing_code(cached = [])
      code = dependency_classes.inject("") do |r,k| 
        cached.include?(k) ? r : r + "Netzke::#{k}".constantize.js_code(cached).strip_js_comments
      end
      code.blank? ? nil : code
    end
    
    def css_missing_code(cached = [])
      code = dependency_classes.inject("") do |r,k| 
        cached.include?(k) ? r : r + "Netzke::#{k}".constantize.css_code(cached)
      end
      code.blank? ? nil : code
    end
  
    #
    # The following methods are used when a widget is generated stand-alone (as a part of a HTML page)
    #

    # instantiating
    def js_widget_instance
      %Q{var #{name.jsonify} = new #{self.class.js_full_class_name}(#{js_config.to_nifty_json});}
    end

    # rendering
    def js_widget_render
      self.class.js_xtype == "netzkewindow" ? %Q{#{name.jsonify}.show();} : %Q{#{name.jsonify}.render("#{name.to_s.split('_').join('-')}-div");}
    end

    # container for rendering
    def js_widget_html
      %Q{<div id="#{name.to_s.split('_').join('-')}-div" style="width:800px;"></div>}
    end

    #
    #
    #
 
    # Widget's actions, tools and menus that are loaded at the moment of instantiation
    def actions; nil; end
    def menu; nil; end
    # def tools; nil; end

    # Little helpers
    def this; "this".l; end
    def null; "null".l; end

    # Methods used to create the javascript class (only once per widget class). 
    # The generated code gets cached at the browser, and the widget intstances (at the browser side)<commit_msg>removed the style property from divs rendered by the netkze helper<commit_after>module Netzke
  # == BaseJs
  # *TODO: outdated*
  # 
  # Module which provides JS-class generation functionality for the widgets ("client-side"). The generated code 
  # is evaluated once per widget class, and the results are cached in the browser. Included into Netzke::Base class.
  # 
  # == Widget javascript code
  # Here's a brief explanation on how a javascript class for a widget gets built.
  # Widget gets defined as a constructor (a function) by +js_class+ class method (see "Inside widget's contstructor").
  # +Ext.extend+ provides inheritance from an Ext class specified in +js_base_class+ class method.
  # 
  # == Inside widget's constructor
  # * Widget's constructor gets called with a parameter that is a configuration object provided by +js_config+ instance method. This configuration is specific for the instance of the widget, and, for example, contains this widget's unique id. As another example, by means of this configuration object, a grid receives the configuration array for its columns, a form - for its fields, etc. With other words, everything that may change from instance to instance of the same widget's class, goes in here.
  # * Widget executes its specific initialization code which is provided by +js_before_consttructor+ class method. 
  # For example, a grid may define its column model, a form - its fields, a tab panel - its tabs ("items").
  # * Widget calls the constructor of the inherited class (see +js_class+ class method) with a parameter that is a merge of 
  # 1) configuration parameter passed to the widget's constructor.
  module BaseJs
    def self.included(base)
      base.extend ClassMethods
    end

    #
    # Instance methods
    #

    # Config that is used for instantiating the widget in javascript
    def js_config
      res = {}
      
      # Unique id of the widget
      res.merge!(:id => global_id)
  
      # Recursively include configs of all non-late aggregatees, so that the widget can instantiate them
      # in javascript immediately.
      non_late_aggregatees.each_pair do |aggr_name, aggr_config|
        aggr_instance = aggregatee_instance(aggr_name.to_sym)
        aggr_instance.before_load
        res["#{aggr_name}_config".to_sym] = aggr_instance.js_config
      end
  
      # Api (besides the default "load_aggregatee_with_cache" - JavaScript side already knows about it)
      api_points = self.class.api_points.reject{ |p| p == :load_aggregatee_with_cache }
      res.merge!(:netzke_api => api_points) unless api_points.empty?
  
      # Widget class name. Needed for dynamic instantiation in javascript.
      # res.merge!(:widget_class_name => short_widget_class_name)
      res.merge!(:scoped_class_name => self.class.js_scoped_class_name)
      
      # Actions, toolbars and menus
      # tools   && res.merge!(:tools   => tools)
      actions && res.merge!(:actions => actions)
      menu    && res.merge!(:menu    => menu)

      # Inform the JavaScript side if persistent_config is enabled
      res[:persistent_config] = persistent_config_enabled?

      # Merge with all config options passed as hash to config[:ext_config]
      res.merge!(ext_config)

      res
    end
  
    # All the JS-code required by this instance of the widget to be instantiated in the browser.
    # It includes the JS-class for the widget itself, as well as JS-classes for all widgets' (non-late) aggregatees.
    def js_missing_code(cached = [])
      code = dependency_classes.inject("") do |r,k| 
        cached.include?(k) ? r : r + "Netzke::#{k}".constantize.js_code(cached).strip_js_comments
      end
      code.blank? ? nil : code
    end
    
    def css_missing_code(cached = [])
      code = dependency_classes.inject("") do |r,k| 
        cached.include?(k) ? r : r + "Netzke::#{k}".constantize.css_code(cached)
      end
      code.blank? ? nil : code
    end
  
    #
    # The following methods are used when a widget is generated stand-alone (as a part of a HTML page)
    #

    # instantiating
    def js_widget_instance
      %Q{var #{name.jsonify} = new #{self.class.js_full_class_name}(#{js_config.to_nifty_json});}
    end

    # rendering
    def js_widget_render
      self.class.js_xtype == "netzkewindow" ? %Q{#{name.jsonify}.show();} : %Q{#{name.jsonify}.render("#{name.to_s.split('_').join('-')}-div");}
    end

    # container for rendering
    def js_widget_html
      %Q{<div id="#{name.to_s.split('_').join('-')}-div"></div>}
    end

    #
    #
    #
 
    # Widget's actions, tools and menus that are loaded at the moment of instantiation
    def actions; nil; end
    def menu; nil; end
    # def tools; nil; end

    # Little helpers
    def this; "this".l; end
    def null; "null".l; end

    # Methods used to create the javascript class (only once per widget class). 
    # The generated code gets cached at the browser, and the widget intstances (at the browser side)
{'fraction_non_alphanumeric': 0.09253279515640767, 'fraction_numerical': 0.0005045408678102926, 'mean_word_length': 3.1712962962962963, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7110805', 'n_tokens_mistral': 2962, 'n_tokens_neox': 2871, 'n_words': 1040}