<commit_before>(function (Q, $, window, undefined) {
	
var Users = Q.Users;

/**
 * Users Tools
 * @module Users-labels
 * @main
 */

/**
 * Tool for inviting users with a label selected from the list of possible labels.
 * @class Users contacts
 * @constructor
 * @param {Object} [options] options for the tool
 *   @param {String} options.communityId Id of community where to need to invite user
 *   @param {String} [options.prefix="Users/"] Pass any prefix here, to filter labels by this prefix
 *  @param {Q.Event} [options.onRefresh] occurs after the tool is refreshed
 *  @param {Q.Event} [options.onClick] occurs when the user clicks or taps a label. Is passed (element, label, title, wasSelected). Handlers may return false to cancel the default behavior of toggling the label.
 */
Q.Tool.define("Users/contacts", function Users_labels_tool(options) {
	var tool = this
	var state = tool.state;

	if (!state.communityId) {
		throw new Q.Exception('communityId not defined');
	}

	Q.Text.get('Users/content', function (err, text) {
		tool.text = text.usersContacts;

		tool.refresh();
	});

	$(tool.element).on(Q.Pointer.fastclick, '.Users_labels_label', function () {
		var $this = $(this);
		state.label = $this.attr('data-label');

		$this.addClass('Q_selected').siblings().removeClass('Q_selected');
	});
},

{
	prefix: 'Users/',
	communityId: null,
	label: null,
	onInvited: new Q.Event()
},

{
	/**
	 * Refresh the tool's contents
	 * @method refresh
	 */
	refresh: function () {
		var tool = this;
		var state = this.state;
		tool.element.addClass('Q_loading');
		var all = state.all;
		if (typeof all === 'string') {
			all = {
				title: all,
				icon: Q.url("{{Users}}/img/icons/labels/all/40.png")
			};
		}
		Q.Users.getLabels(state.communityId, state.prefix, function (err, labels) {
			Q.Template.render("Users/labels", {
				labels: labels,
				all: all,
				canAdd: tool.text.inviteUser,
				canAddIcon: Q.url('{{Q}}/img/actions/add.png')
			}, function (err, html) {
				tool.element.removeClass('Q_loading');
				tool.element.innerHTML = html;
				Q.handle(state.onRefresh, tool, []);
			});

			var $add = tool.$('.Users_labels_add').on(Q.Pointer.fastclick, function () {

				if(!state.label) {
					return Q.alert(tool.text.selectLabel);
				}

				Q.Streams.invite(state.communityId, 'Streams/experience/main', {
					addLabel: state.label
				}, function () {
					Q.handle(state.onInvited, tool);
				});
			});

			setTimeout(function () {
				// add clickable after the sizing has been done
				$add.plugin('Q/clickable');
			}, 0);
		});
	}
}

);

Q.Template.set('Users/labels', ''
+ '<ul>'
+ '{{#if all}}'
+ '<li class="Users_labels_label" data-label="*">'
+   '<img class="Users_labels_icon" src="{{all.icon}}" alt="all">'
+   '<div class="Users_labels_title">{{all.title}}</div>'
+ '</li>'
+ '{{/if}}'
+ '{{#each labels}}'
+ '<li class="Users_labels_label" data-label="{{this.label}}">'
+   '<img class="Users_labels_icon" src="{{call "iconUrl"}}" alt="label icon">'
+   '<div class="Users_labels_title">{{this.title}}</div>'
+ '</li>'
+ '{{/each}}'
+ '<li class="Users_labels_action Users_labels_add">'
+   '<img class="Users_labels_icon" src="{{canAddIcon}}">'
+   '<div class="Users_labels_title">{{canAdd}}</div>'
+ '</li>'
+ '<ul>');

})(Q, jQuery, window);<commit_msg>Modified Users/contatcs tool. Added state.canAdd which define whether add button "Invite User". Added state.onClick event which run onclick labels and can revoke handler actions if result is false. Fixed some bugs and refactored code.<commit_after>(function (Q, $, window, undefined) {
	
var Users = Q.Users;

/**
 * Users Tools
 * @module Users-labels
 * @main
 */

/**
 * Tool for inviting users with a label selected from the list of possible labels.
 * @class Users contacts
 * @constructor
 * @param {Object} [options] options for the tool
 *   @param {String} options.communityId Id of community where to need to invite user
 *   @param {String} [options.prefix="Users/"] Pass any prefix here, to filter labels by this prefix
 *  @param {Q.Event} [options.onRefresh] occurs after the tool is refreshed
 *  @param {Q.Event} [options.onClick] occurs when the user clicks or taps a label. Is passed (element, label, title, wasSelected). Handlers may return false to cancel the default behavior of toggling the label.
 *  @param {Q.Event} [options.onInvited] occurs when the user invited.
 */
Q.Tool.define("Users/contacts", function Users_labels_tool(options) {
	var tool = this
	var state = tool.state;

	if (!state.communityId) {
		throw new Q.Exception('communityId not defined');
	}

	Q.Text.get('Users/content', function (err, text) {
		tool.text = text.usersContacts;

		tool.refresh();
	});
},

{
	prefix: 'Users/',
	communityId: null,
	canAdd: true,
	onRefresh: new Q.Event(),
	onClick: new Q.Event(),
	onInvited: new Q.Event()
},

{
	/**
	 * Refresh the tool's contents
	 * @method refresh
	 */
	refresh: function () {
		var tool = this;
		var state = this.state;
		tool.element.addClass('Q_loading');
		var all = state.all;
		if (typeof all === 'string') {
			all = {
				title: all,
				icon: Q.url("{{Users}}/img/icons/labels/all/40.png")
			};
		}

		var selectedLabel = null;

		Q.Users.getLabels(state.communityId, state.prefix, function (err, labels) {
			Q.Template.render("Users/labels", {
				labels: labels,
				all: all,
				canAdd: state.canAdd,
				canAddText: tool.text.inviteUser,
				canAddIcon: Q.url('{{Q}}/img/actions/add.png')
			}, function (err, html) {
				tool.element.removeClass('Q_loading');
				tool.element.innerHTML = html;

				$('.Users_labels_label', tool.element).on(Q.Pointer.fastclick, function () {
					var $this = $(this);
					selectedLabel = $this.attr('data-label');
					var labelTitle = $(".Users_labels_title", $this).text();

					if (false === Q.handle(state.onClick, tool, [selectedLabel, labelTitle])) {
						return;
					};

					$this.addClass('Q_selected').siblings().removeClass('Q_selected');
				});

				$('.Users_labels_add', tool.element).on(Q.Pointer.fastclick, function () {

					if(!selectedLabel) {
						return Q.alert(tool.text.selectLabel);
					}

					Q.Streams.invite(state.communityId, 'Streams/experience/main', {
						addLabel: selectedLabel
					}, function () {
						Q.handle(state.onInvited, tool);
					});
				});

				Q.handle(state.onRefresh, tool, []);
			});
		});
	}
}

);

Q.Template.set('Users/labels', ''
+ '<ul>'
+ '{{#if all}}'
+ '<li class="Users_labels_label" data-label="*">'
+   '<img class="Users_labels_icon" src="{{all.icon}}" alt="all">'
+   '<div class="Users_labels_title">{{all.title}}</div>'
+ '</li>'
+ '{{/if}}'
+ '{{#each labels}}'
+ '<li class="Users_labels_label" data-label="{{this.label}}">'
+   '<img class="Users_labels_icon" src="{{call "iconUrl"}}" alt="label icon">'
+   '<div class="Users_labels_title">{{this.title}}</div>'
+ '</li>'
+ '{{/each}}'
+ '{{#if canAdd}}'
+ '<li class="Users_labels_action Users_labels_add Q/clickable">'
+   '<img class="Users_labels_icon" src="{{canAddIcon}}">'
+   '<div class="Users_labels_title">{{canAddText}}</div>'
+ '</li>'
+ '{{/if}}'
+ '<ul>');

})(Q, jQuery, window);
{'fraction_non_alphanumeric': 0.1845529592836155, 'fraction_numerical': 0.0006995942353435008, 'mean_word_length': 3.9026063100137174, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '6639095', 'n_tokens_mistral': 2672, 'n_tokens_neox': 2390, 'n_words': 574}