<commit_before>/**
 * (c) Copyright 2002-2017 by authors of the Tiki Wiki CMS Groupware Project
 *
 * All Rights Reserved. See copyright.txt for details and a complete list of authors.
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
 * $Id$
 *
 * Handles list plugin GUI
 */


// event for plugin list
$(document)
	.off('plugin_list_ready')
	.on('plugin_list_ready', function (params) {

		var $textarea = params.modal.find("textarea[name=content]");
		jqueryTiki.plugins.list.setup($textarea);

	});

$(document).ready(function () {

	jqueryTiki.plugins = jqueryTiki.plugins || {};

	jqueryTiki.plugins.list = {
		/**
		 * Local data
		 */
		current: {},
		fields: {},
		plugins: {},
		objectType: null,
		$editor: null,

		/**
		 * Main GUI setup
		 *
		 * @param $textarea
		 */
		setup: function ($textarea) {

			var gui = this;

			gui.current = {};
			gui.fields = {};
			gui.plugins = {};
			gui.objectType = null;
			gui.sortableOptions = {
				listType: "ul",
				maxLevels: 2,
				handle: "div:first",
				items: "li",
				disableNesting: "no-nesting"
			};

			// display GUI interface here
			gui.$editor = $("<div>")
				.addClass('plugin-list-editor clearfix');

			var buildToolbar = function () {
				var $tb = $("<div>")
					.addClass("btn-toolbar")
					.append(
						$("<div>")
							.addClass("btn-group")
							.append(
								$("<a>")
									.addClass("btn btn-default btn-sm btn-source")
									.append(
										$("<span>").getIcon("list"),
										" ",
										tr("Source")
									)
									.click(function () {
										toggleGui();
									})
									.attr("title", tr("Toggle source mode"))
							),
						gui.buildDropDown(gui.arrayKeys(gui.plugins), tr("Add plugin"), function () {
							if ($(this).data("value")) {
								$ul.append(
									gui.addPlugin({
										name: $(this).data("value"),
										params: [],
										plugins: []
									})
								).nestedSortable(gui.sortableOptions);


								return false;
							}
							$(".dropdown-menu", $tb).hide();
						})
					);

				$(".dropdown-toggle", $tb).removeClass("btn-link btn-xs").addClass("btn-default btn-sm");

				return $tb;
			};

			var $toolbar = buildToolbar();
			gui.$editor.append($toolbar);

			var $ul = $("<ul>")
				.addClass('plugin-list-gui clearfix')
				.appendTo(gui.$editor);

			var toggleGui = function () {
				var $btn = gui.$editor.find(".btn-source");
				if ($textarea.is(":visible")) {
					showGui();

					$btn.empty().append($("<span>").getIcon("list"), tr("Source"));

					$(".dropdown-toggle", gui.$editor)
						.removeClass("disabled")
						.css("opacity", 1);
				} else {

					gui.saveToTextarea();

					$textarea.show();
					$ul.hide();

					$btn.empty().append($("<span>").getIcon("mouse-pointer"), tr("GUI"));

					$(".dropdown-toggle", gui.$editor)
						.addClass("disabled")
						.css("opacity", 0.3);
				}
			};

			var showGui = function () {
				$textarea.tikiModal(tr("Loading..."));
				$.getJSON(
					$.service("plugin", "list_edit"),
					{
						body: $textarea.val()
					},
					function (data) {
						if (data) {
							$textarea.hide();
							$ul.empty().show();
							$(".gui-only", $toolbar)
								.prop("disabled", false)
								.css("opacity", 1);

							gui.current = data.current;
							gui.plugins = data.plugins;
							gui.fields = data.fields;
							gui.fields.formatted = [];

							for (var p in gui.current) {	// check for format names and add to fields
								if (gui.current.hasOwnProperty(p)) {

									if (gui.current[p].name === "format" && typeof gui.current[p].params.name !== "undefined") {
										gui.fields.formatted.push(gui.current[p].params.name);
									}
								}
							}

							for (p in gui.current) {
								if (gui.current.hasOwnProperty(p)) {

									$ul.append(
										gui.addPlugin(gui.current[p])
									);
								}
							}

							if (jqueryTiki.chosen) {
								gui.$editor.find("select").trigger("chosen:updated");
							}

							$toolbar.replaceWith(buildToolbar()).applyChosen();
							$textarea.tikiModal();
						}
					}
				);
<commit_msg>[FIX] list gui: Fall back to source editing if the syntax doesn't work (yet) with the GUI<commit_after>/**
 * (c) Copyright 2002-2017 by authors of the Tiki Wiki CMS Groupware Project
 *
 * All Rights Reserved. See copyright.txt for details and a complete list of authors.
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
 * $Id$
 *
 * Handles list plugin GUI
 */


// event for plugin list
$(document)
	.off('plugin_list_ready')
	.on('plugin_list_ready', function (params) {

		var $textarea = params.modal.find("textarea[name=content]");
		jqueryTiki.plugins.list.setup($textarea);

	});

$(document).ready(function () {

	jqueryTiki.plugins = jqueryTiki.plugins || {};

	jqueryTiki.plugins.list = {
		/**
		 * Local data
		 */
		current: {},
		fields: {},
		plugins: {},
		objectType: null,
		$editor: null,

		/**
		 * Main GUI setup
		 *
		 * @param $textarea
		 */
		setup: function ($textarea) {

			var gui = this;

			gui.current = {};
			gui.fields = {};
			gui.plugins = {};
			gui.objectType = null;
			gui.sortableOptions = {
				listType: "ul",
				maxLevels: 2,
				handle: "div:first",
				items: "li",
				disableNesting: "no-nesting"
			};

			// display GUI interface here
			gui.$editor = $("<div>")
				.addClass('plugin-list-editor clearfix');

			var buildToolbar = function () {
				var $tb = $("<div>")
					.addClass("btn-toolbar")
					.append(
						$("<div>")
							.addClass("btn-group")
							.append(
								$("<a>")
									.addClass("btn btn-default btn-sm btn-source")
									.append(
										$("<span>").getIcon("list"),
										" ",
										tr("Source")
									)
									.click(function () {
										toggleGui();
									})
									.attr("title", tr("Toggle source mode"))
							),
						gui.buildDropDown(gui.arrayKeys(gui.plugins), tr("Add plugin"), function () {
							if ($(this).data("value")) {
								$ul.append(
									gui.addPlugin({
										name: $(this).data("value"),
										params: [],
										plugins: []
									})
								).nestedSortable(gui.sortableOptions);


								return false;
							}
							$(".dropdown-menu", $tb).hide();
						})
					);

				$(".dropdown-toggle", $tb).removeClass("btn-link btn-xs").addClass("btn-default btn-sm");

				return $tb;
			};

			var $toolbar = buildToolbar();
			gui.$editor.append($toolbar);

			var $ul = $("<ul>")
				.addClass('plugin-list-gui clearfix')
				.appendTo(gui.$editor);

			var toggleGui = function () {
				var $btn = gui.$editor.find(".btn-source");
				if ($textarea.is(":visible")) {
					showGui();

					$btn.empty().append($("<span>").getIcon("list"), tr("Source"));

					$(".dropdown-toggle", gui.$editor)
						.removeClass("disabled")
						.css("opacity", 1);
				} else {

					gui.saveToTextarea();

					$textarea.show();
					$ul.hide();

					$btn.empty().append($("<span>").getIcon("mouse-pointer"), tr("GUI"));

					$(".dropdown-toggle", gui.$editor)
						.addClass("disabled")
						.css("opacity", 0.3);
				}
			};

			var showGui = function () {
				$textarea.tikiModal(tr("Loading..."));
				$.getJSON(
					$.service("plugin", "list_edit"),
					{
						body: $textarea.val()
					},
					function (data) {
						try {
							if (data) {
								$textarea.hide();
								$ul.empty().show();
								$(".gui-only", $toolbar)
									.prop("disabled", false)
									.css("opacity", 1);

								gui.current = data.current;
								gui.plugins = data.plugins;
								gui.fields = data.fields;
								gui.fields.formatted = [];

								for (var p in gui.current) {	// check for format names and add to fields
									if (gui.current.hasOwnProperty(p)) {

										if (gui.current[p].name === "format" && typeof gui.current[p].params.name !== "undefined") {
											gui.fields.formatted.push(gui.current[p].params.name);
										}
									}
								}

								for (p in gui.current) {
									if (gui.current.hasOwnProperty(p)) {

										$ul.append(
											gui.addPlugin(gui.current[p])
										);
									}
								}

								if (jqueryTiki.chosen) {
									gui.$editor.find("select").trigger("chosen:updated");
								}

								$toolbar.replaceWith(buildToolbar()).applyChosen();
								$textarea.tikiModal();
							}
						}
						catch(e) {
							$ul.empty().hide();
							$toolbar.hide();
							$textarea
								.tikiModal()
								.show()
								.showError(tr("List plugin syntax is currently not compatible with the GUI, so source editing only is available."));
						}
					}
				);

{'fraction_non_alphanumeric': 0.18326234603430414, 'fraction_numerical': 0.0029929780131230576, 'mean_word_length': 2.1661807580174925, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 19, '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': '2251074', 'n_tokens_mistral': 4104, 'n_tokens_neox': 2710, 'n_words': 543}