Overview
Comment:Input lists: implement multiple choice
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 12cfcd4abf1af91a6a4d02b7aef9605b94d9edfa
User & Date: bohwaz on 2020-09-29 16:53:48
Other Links: branch diff | manifest | tags
Context
2020-09-29
17:24
Allow d/m/Y date format check-in: e4d78127c5 user: bohwaz tags: dev
16:53
Input lists: implement multiple choice check-in: 12cfcd4abf user: bohwaz tags: dev
16:53
Move query building logic in class for quick member search check-in: 1b4976cf19 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Template.php from [26eb4fe83a] to [ffeeb083b6].

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
283
284
285
286
287
288
289










290
291
292
293
294


295
296
297

298
299
300
301
302
303
304

		return sprintf('<a href="%s" class="icn" title="%s">%s</a>', $this->escape(ADMIN_URL . $params['href']), $this->escape($params['label']), Utils::iconUnicode($params['shape']));
	}

	protected function widgetButton(array $params): string
	{
		$icon = Utils::iconUnicode($params['shape']);
		$label = $this->escape($params['label']);
		unset($params['label'], $params['shape']);

		array_walk($params, function (&$v, $k) {
			$v = sprintf('%s="%s"', $k, $this->escape($v));
		});

		$params = implode(' ', $params);
................................................................................
		// Create attributes string
		if (array_key_exists('required', $attributes)) {
			$attributes['required'] = 'required';
		}

		$attributes_string = $attributes;

		if ($type == 'list') {
			unset($attributes_string['target'], $attributes_string['multiple']);
		}

		array_walk($attributes_string, function (&$v, $k) {
			$v = sprintf('%s="%s"', $k, $v);
		});

		$attributes_string = implode(' ', $attributes_string);

		if ($type == 'select') {
................................................................................
			$input .= '</select>';
		}
		elseif ($type == 'textarea') {
			$input = sprintf('<textarea %s>%s</textarea>', $attributes_string, $this->escape($current_value));
		}
		elseif ($type == 'list') {
			$multiple = !empty($attributes['multiple']);











			$button = $this->widgetButton([
				'shape' => $multiple ? 'plus' : 'menu',
				'value' => $attributes['target'],
				'label' => $multiple ? 'Ajouter' : 'Sélectionner'


			]);

			$input = sprintf('<span id="%s_container" class="input-list">%s<input type="hidden" value="%s" %s /><span class="label">%3$s</span></span>', $this->escape($attributes['id']), $button, $this->escape($current_value), $attributes_string);

		}
		elseif ($type == 'money') {
			$currency = Config::getInstance()->get('monnaie');
			$input = sprintf('<input type="text" pattern="[0-9.,]*" inputmode="decimal" size="8" class="money" %s value="%s" /><b>%s</b>', $attributes_string, $this->escape($current_value), $currency);
		}
		else {
			$input = sprintf('<input type="%s" %s value="%s" />', $type, $attributes_string, $this->escape($current_value));







|







 







<
<
<
<







 







>
>
>
>
>
>
>
>
>
>




|
>
>


<
>







173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
244
245
246
247
248
249
250




251
252
253
254
255
256
257
...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312

		return sprintf('<a href="%s" class="icn" title="%s">%s</a>', $this->escape(ADMIN_URL . $params['href']), $this->escape($params['label']), Utils::iconUnicode($params['shape']));
	}

	protected function widgetButton(array $params): string
	{
		$icon = Utils::iconUnicode($params['shape']);
		$label = isset($params['label']) ? $this->escape($params['label']) : '';
		unset($params['label'], $params['shape']);

		array_walk($params, function (&$v, $k) {
			$v = sprintf('%s="%s"', $k, $this->escape($v));
		});

		$params = implode(' ', $params);
................................................................................
		// Create attributes string
		if (array_key_exists('required', $attributes)) {
			$attributes['required'] = 'required';
		}

		$attributes_string = $attributes;





		array_walk($attributes_string, function (&$v, $k) {
			$v = sprintf('%s="%s"', $k, $v);
		});

		$attributes_string = implode(' ', $attributes_string);

		if ($type == 'select') {
................................................................................
			$input .= '</select>';
		}
		elseif ($type == 'textarea') {
			$input = sprintf('<textarea %s>%s</textarea>', $attributes_string, $this->escape($current_value));
		}
		elseif ($type == 'list') {
			$multiple = !empty($attributes['multiple']);
			$values = '';
			$delete_btn = $this->widgetButton(['shape' => 'minus']);

			if (!is_array($current_value)) {
				$current_value = [];
			}

			foreach ($current_value as $v => $l) {
				$values .= sprintf('<span class="label"><input type="hidden" name="%s[%s]" value="%s" /> %3$s %s</span>', $this->escape($name), $this->escape($v), $this->escape($l), $multiple ? $delete_btn : '');
			}

			$button = $this->widgetButton([
				'shape' => $multiple ? 'plus' : 'menu',
				'value' => $attributes['target'],
				'label' => $multiple ? 'Ajouter' : 'Sélectionner',
				'data-multiple' => $multiple ? '1' : '0',
				'data-name' => $name,
			]);


			$input = sprintf('<span id="%s_container" class="input-list">%s%s</span>', $this->escape($attributes['id']), $button, $values);
		}
		elseif ($type == 'money') {
			$currency = Config::getInstance()->get('monnaie');
			$input = sprintf('<input type="text" pattern="[0-9.,]*" inputmode="decimal" size="8" class="money" %s value="%s" /><b>%s</b>', $attributes_string, $this->escape($current_value), $currency);
		}
		else {
			$input = sprintf('<input type="%s" %s value="%s" />', $type, $attributes_string, $this->escape($current_value));

Modified src/templates/acc/transactions/new.tpl from [4013a944f1] to [ce2915f3db].

262
263
264
265
266
267
268
269
270














271
272
273
274
275
276
277
278
279
		initLine(n);
		line.parentNode.appendChild(n);
	};
}

function inputListSelected(value, label) {
	var i = g.current_list_input;
	i.parentNode.querySelector('input[type=hidden]').value = value;
	i.parentNode.querySelector('span.label').innerHTML = label;














	g.closeDialog();
	i.focus();
}

initForm();
</script>
{/literal}

{include file="admin/_foot.tpl"}







|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>









262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
		initLine(n);
		line.parentNode.appendChild(n);
	};
}

function inputListSelected(value, label) {
	var i = g.current_list_input;
	var multiple = i.firstChild.getAttribute('data-multiple');
	var name = i.getAttribute('data-name');

	var span = document.createElement('span');
	span.className = 'label';
	span.innerHTML = '<input type="hidden" name="' + name + '[' + value + ']" value="' + label + '" />' + label;
	if (parseInt(multiple, 10) == 1) {
		var btn = document.createElement('button');
		btn.className = 'icn-btn';
		btn.type = 'button';
		btn.setAttribute('data-icon', '✘');
		btn.onclick = () => span.parentNode.removeChild(span);
		span.appendChild(btn);
	}
	console.log(multiple, multiple ? 1 : 2, i);
	i.appendChild(span);
	g.closeDialog();
	i.focus();
}

initForm();
</script>
{/literal}

{include file="admin/_foot.tpl"}

Modified src/www/admin/static/admin.css from [ae7c16ef28] to [96d6e1e894].

376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393






394
395
396
397
398
399
400
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: start;
    min-width: 0;
}

form .input-list span.label {
    padding: .4rem .6rem;
}

form .input-list button {
    padding: .4rem .6rem;
    margin: 0;
    border: none;
    border-right: 1px solid #ccc;
    border-radius: 0;
}







input[readonly] {
    color: #666;
    background-color: #eee;
}

input.money {







|










>
>
>
>
>
>







376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: start;
    min-width: 0;
}

form .input-list .label {
    padding: .4rem .6rem;
}

form .input-list button {
    padding: .4rem .6rem;
    margin: 0;
    border: none;
    border-right: 1px solid #ccc;
    border-radius: 0;
}

form .input-list .label button {
    padding: .2rem;
    border: none;
    background: none;
}

input[readonly] {
    color: #666;
    background-color: #eee;
}

input.money {