PageSourceSearch

https://mecklenburg-schwerin.de/export/sites/tvms/_conf/system/js/ajax/core/AbstractManager.js

js mecklenburg-schwerin.de collected 2026-10-04 02:04:05 UTC 4,797 bytes, 158 lines download raw bytes

1(function (callback) {
2  if (typeof define === 'function' && define.amd) {
3    define(['core/Core'], callback);
4  }
5  else {
6    callback();
7  }
8}(function () {
9
10/**
11 * The Manager acts as the controller in a Model-View-Controller framework. All
12 * public calls should be performed on the manager object.
13 *
14 * @param properties A map of fields to set. Refer to the list of public fields.
15 * @class AbstractManager
16 */
17AjaxSolr.AbstractManager = AjaxSolr.Class.extend(
18  /** @lends AjaxSolr.AbstractManager.prototype */
19  {
20  /**
21   * @param {Object} [attributes]
22   * @param {String} [attributes.solrUrl] The fully-qualified URL of the Solr
23   *   application. You must include the trailing slash. Do not include the path
24   *   to any Solr servlet. Defaults to "http://localhost:8983/solr/"
25   * @param {String} [attributes.proxyUrl] If we want to proxy queries through a
26   *   script, rather than send queries to Solr directly, set this field to the
27   *   fully-qualified URL of the script.
28   * @param {String} [attributes.servlet] The default Solr servlet. You may
29   *   prepend the servlet with a core if using multiple cores. Defaults to
30   *   "servlet".
31   */
32  constructor: function (attributes) {
33    AjaxSolr.extend(this, {
34      solrUrl: 'http://localhost:8983/solr/',
35      proxyUrl: null,
36      servlet: 'select',
37      // The most recent response from Solr.
38      response: {},
39      // A collection of all registered widgets.
40      widgets: {},
41      // The parameter store for the manager and its widgets.
42      store: null,
43      // Whether <tt>init()</tt> has been called yet.
44      initialized: false
45    }, attributes);
46  },
47
48  /**
49   * An abstract hook for child implementations.
50   *
51   * <p>This method should be called after the store and the widgets have been
52   * added. It should initialize the widgets and the store, and do any other
53   * one-time initializations, e.g., perform the first request to Solr.</p>
54   *
55   * <p>If no store has been set, it sets the store to the basic <tt>
56   * AjaxSolr.ParameterStore</tt>.</p>
57   */
58  init: function () {
59    this.initialized = true;
60    if (this.store === null) {
61      this.setStore(new AjaxSolr.ParameterStore());
62    }
63    this.store.load(false);
64    for (var widgetId in this.widgets) {
65      this.widgets[widgetId].init();
66    }
67    this.store.init();
68  },
69
70  /**
71   * Set the manager's parameter store.
72   *
73   * @param {AjaxSolr.ParameterStore} store
74   */
75  setStore: function (store) { 
76    store.manager = this;
77    this.store = store;
78  },
79
80  /** 
81   * Adds a widget to the manager.
82   *
83   * @param {AjaxSolr.AbstractWidget} widget
84   */
85  addWidget: function (widget) { 
86    widget.manager = this;
87    this.widgets[widget.id] = widget;
88  },
89
90  /** 
91   * Stores the Solr parameters to be sent to Solr and sends a request to Solr.
92   *
93   * @param {Boolean} [start] The Solr start offset parameter.
94   * @param {String} [servlet] The Solr servlet to send the request to.
95   */
96  doRequest: function (start, servlet) {
97    if (this.initialized === false) {
98      this.init();
99    }
100    // Allow non-pagination widgets to reset the offset parameter.
101    if (start !== undefined) {
102      this.store.get('start').val(start);
103    }
104    if (servlet === undefined) {
105      servlet = this.servlet;
106    }
107
108    this.store.save();
109
110    for (var widgetId in this.widgets) {
111      this.widgets[widgetId].beforeRequest();
112    }
113
114    this.executeRequest(servlet);
115  },
116
117  /**
118   * An abstract hook for child implementations.
119   *
120   * <p>Sends the request to Solr, i.e. to <code>this.solrUrl</code> or <code>
121   * this.proxyUrl</code>, and receives Solr's response. It should pass Solr's
122   * response to <code>handleResponse()</code> for handling.</p>
123   *
124   * <p>See <tt>managers/Manager.jquery.js</tt> for a jQuery implementation.</p>
125   *
126   * @param {String} servlet The Solr servlet to send the request to.
127   * @param {String} string The query string of the request. If not set, it
128   *   should default to <code>this.store.string()</code>
129   * @throws If not defined in child implementation.
130   */
131  executeRequest: function (servlet, string) {
132    throw 'Abstract method executeRequest must be overridden in a subclass.';
133  },
134
135  /**
136   * This method is executed after the Solr response data arrives. Allows each
137   * widget to handle Solr's response separately.
138   *
139   * @param {Object} data The Solr response.
140   */
141  handleResponse: function (data) {
142    this.response = data;
143    for (var widgetId in this.widgets) {
144      this.widgets[widgetId].afterRequest();
145    }
146  },
147
148  /**
149   * This method is executed if Solr encounters an error.
150   *
151   * @param {String} message An error message.
152   */
153  handleError: function (message) {
154    window.console && console.log && console.log(message);
155  }
156});
157
158}));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.