<commit_before>/*jslint white:true, nomen: true, plusplus: true */
/*global mx, define, require, browser, devel, console, logger, mendix */
/*mendix */

define([
	"dojo/_base/declare",
	"mxui/widget/_WidgetBase",
	"dijit/_TemplatedMixin",
	"mxui/dom",
	"dojo/dom-class",
	"dojo/dom-style",
	"dojo/dom-construct",
	"dojo/_base/array",
	"dojo/_base/lang",
	"LabelSelect/lib/jquery-1.11.2",
	"dojo/text!LabelSelect/widget/template/LabelSelect.html"
], function (declare, _WidgetBase, _TemplatedMixin, dom, domClass, domStyle, domConstruct, dojoArray, lang, _jQuery, widgetTemplate) {
	"use strict";

	var $ = _jQuery.noConflict(true);

	return declare("LabelSelect.widget.LabelSelect", [_WidgetBase, _TemplatedMixin], {
		templateString: widgetTemplate,

		_handles: null,
		_contextObj: null,
		_listBox: null,
		_tagEntity: null,
		_tagAttribute: null,
		_colorAttribute: null,
		_refAttribute: null,
		_tagCache: null,

		_readOnly: false,

		_constructed: false,

		postCreate: function () {
			logger.debug(this.id + ".postCreate");
			//set the variables:
			this._handles = [];
			this._tagEntity = this.tagAssoc.split("/")[1];
			this._refAttribute = this.tagAssoc.split("/")[0];
			this._tagAttribute = this.tagAttrib.split("/")[2];
			this._colorAttribute = this.colorAttrib.split("/")[2];
			this._tagCache = {}; //we need this to set references easily.

			this._readOnly = this.readOnly || this.get("disabled") || this.readonly;
		},

		update: function (obj, callback) {
			logger.debug(this.id + ".update");

			if (!this._constructed) {
				this._listBox = domConstruct.create("ul", {
					"id": this.id + "_ListBox"
				});
				domConstruct.place(this._listBox, this.domNode);
				this._constructed = true;
			}

			if (obj) {
				domStyle.set(this.domNode, "visibility", "visible");

				this._contextObj = obj;
				this._fetchCurrentLabels(callback);

				this._resetSubscriptions();
			} else {
				domStyle.set(this.domNode, "visibility", "hidden");
				callback();
			}
		},

		_fetchCurrentLabels: function (callback) {
			logger.debug(this.id + "._fetchCurrentLabels");
			//fetch all referenced labels
			var xpath = "//" + this._tagEntity + this.tagConstraint.replace("[%CurrentObject%]", this._contextObj.getGuid());
			var filters = {};
			if (this.sortAttr && this.sortOrder) {
				filters.sort = [[this.sortAttr, this.sortOrder]];
			}
			mx.data.get({
				xpath: xpath,
				filters : filters,
				callback: lang.hitch(this, this._processTags, callback),
				error: lang.hitch(this, function (err) {
					console.error(this.id + "._fetchCurrentLabels get failed, err: " + err.toString());
					mendix.lang.nullExec(callback);
				})
			});
		},

		_processTags: function (callback, objs) {
			logger.debug(this.id + "._processTags");
			var refObjs = this._contextObj.get(this._refAttribute),<commit_msg>Fix issue with filter sorting not working<commit_after>/*jslint white:true, nomen: true, plusplus: true */
/*global mx, define, require, browser, devel, console, logger, mendix */
/*mendix */

define([
	"dojo/_base/declare",
	"mxui/widget/_WidgetBase",
	"dijit/_TemplatedMixin",
	"mxui/dom",
	"dojo/dom-class",
	"dojo/dom-style",
	"dojo/dom-construct",
	"dojo/_base/array",
	"dojo/_base/lang",
	"LabelSelect/lib/jquery-1.11.2",
	"dojo/text!LabelSelect/widget/template/LabelSelect.html"
], function (declare, _WidgetBase, _TemplatedMixin, dom, domClass, domStyle, domConstruct, dojoArray, lang, _jQuery, widgetTemplate) {
	"use strict";

	var $ = _jQuery.noConflict(true);

	return declare("LabelSelect.widget.LabelSelect", [_WidgetBase, _TemplatedMixin], {
		templateString: widgetTemplate,

		_handles: null,
		_contextObj: null,
		_listBox: null,
		_tagEntity: null,
		_tagAttribute: null,
		_colorAttribute: null,
		_refAttribute: null,
		_tagCache: null,

		_readOnly: false,

		_constructed: false,

		postCreate: function () {
			logger.debug(this.id + ".postCreate");
			//set the variables:
			this._handles = [];
			this._tagEntity = this.tagAssoc.split("/")[1];
			this._refAttribute = this.tagAssoc.split("/")[0];
			this._tagAttribute = this.tagAttrib.split("/")[2];
			this._colorAttribute = this.colorAttrib.split("/")[2];
			this._tagCache = {}; //we need this to set references easily.

			this._readOnly = this.readOnly || this.get("disabled") || this.readonly;
		},

		update: function (obj, callback) {
			logger.debug(this.id + ".update");

			if (!this._constructed) {
				this._listBox = domConstruct.create("ul", {
					"id": this.id + "_ListBox"
				});
				domConstruct.place(this._listBox, this.domNode);
				this._constructed = true;
			}

			if (obj) {
				domStyle.set(this.domNode, "visibility", "visible");

				this._contextObj = obj;
				this._fetchCurrentLabels(callback);

				this._resetSubscriptions();
			} else {
				domStyle.set(this.domNode, "visibility", "hidden");
				callback();
			}
		},

		_fetchCurrentLabels: function (callback) {
			logger.debug(this.id + "._fetchCurrentLabels");
			//fetch all referenced labels
			var xpath = "//" + this._tagEntity + this.tagConstraint.replace("[%CurrentObject%]", this._contextObj.getGuid());
			var filters = {};
			if (this.sortAttr && this.sortOrder) {
				filters.sort = [[this.sortAttr, this.sortOrder]];
			}
			mx.data.get({
				xpath: xpath,
				filter : filters,
				callback: lang.hitch(this, this._processTags, callback),
				error: lang.hitch(this, function (err) {
					console.error(this.id + "._fetchCurrentLabels get failed, err: " + err.toString());
					mendix.lang.nullExec(callback);
				})
			});
		},

		_processTags: function (callback, objs) {
			logger.debug(this.id + "._processTags");
			var refObjs = this._contextObj.get(this._refAttribute),
{'fraction_non_alphanumeric': 0.16241870275971174, 'fraction_numerical': 0.0028124450694322375, 'mean_word_length': 3.909404659188956, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '1771233', 'n_tokens_mistral': 2222, 'n_tokens_neox': 1918, 'n_words': 365}