Skip to content

Commit 0a4e797

Browse files
authored
Merge pull request #10 from sinanatra/refactor-properties
Refactor properties
2 parents 2bf5283 + 444f51f commit 0a4e797

4 files changed

Lines changed: 53 additions & 40 deletions

File tree

Module.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
<?php
22
namespace NestedDataType;
33

4+
use Laminas\Mvc\MvcEvent;
45
use Omeka\Module\AbstractModule;
56
use Laminas\EventManager\Event;
67
use Laminas\EventManager\SharedEventManagerInterface;
78

89
class Module extends AbstractModule
910
{
11+
1012
public function getConfig()
1113
{
1214
return include __DIR__ . '/config/module.config.php';
1315
}
1416

17+
public function onBootstrap(MvcEvent $event): void
18+
{
19+
parent::onBootstrap($event);
20+
$acl = $this->getServiceLocator()->get('Omeka\Acl');
21+
$acl->allow(null, 'NestedDataType\Controller\Index');
22+
}
23+
1524
public function attachListeners(SharedEventManagerInterface $sharedEventManager)
1625
{
1726
$sharedEventManager->attach(

asset/js/nesteddatatype.js

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,33 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
1919
renderedLink = repeatProperty.find('.items');
2020
}
2121

22-
const cloneItem = () => {
23-
container.append(container.find('.nested-data-type_repeat_property').last().clone());
22+
const cloneItem = (idx) => {
23+
let item = `
24+
<div class="nested-data-type_repeat_property">
25+
<div class="nested-data-type_repeat_property_list">
26+
<input class="nested-data-type-dropwdown nested-data-type_property_dropdown" list="property-dropdown" data-value-key="property-label-${idx}" placeholder="Select a property" />
27+
<button class="nested-data-type_button o-icon-add nested-data-type_add_class"></button>
28+
</div>
29+
<div class="nested-data-type_repeat_class hidden">
30+
<input class="nested-data-type-dropwdown inner-class" list="class-dropdown" data-value-key="inner-class-${idx}" placeholder="Select a class" />
31+
<input class="nested-data-type-dropwdown inner-property" list="property-dropdown" data-value-key="inner-property-${idx}" placeholder="Select a property" />
32+
</div>
33+
<div class="input">
34+
<label class="value">
35+
<textarea class="property-value" name="property-value" data-value-key="property-value-${idx}"></textarea>
36+
</label>
37+
</div>
38+
<div class="input hidden">
39+
<label class="value-uri">
40+
<textarea class="property-uri" name="property-uri" data-value-key="property-uri-${idx}"></textarea>
41+
</label>
42+
</div>
43+
<input type="hidden" class="nested-data-type_is-hidden" data-value-key="is-hidden-${idx}" />
44+
<button class="nested-data-type_button o-icon-public nested-data-type_hide_property"></button>
45+
<button class="nested-data-type_button o-icon-delete nested-data-type_remove_property"></button>
46+
</div>`;
47+
48+
container.append(container.append(item));
2449
}
2550

2651
const structureField = (obj, type, insertVal = '') => {
@@ -36,22 +61,14 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
3661
addBtn.on('click', function (e) {
3762
e.preventDefault();
3863
const num = container.find('.nested-data-type_repeat_property').length;
39-
cloneItem();
64+
cloneItem(num + 1);
4065
findItems();
4166

4267
if (renderedLink) {
4368
renderedLink.remove();
4469
textareaValue.parent().parent().css('display', 'block');
45-
// textareaUri.parent().parent().css('display', 'block')
4670
}
4771

48-
structureField(isHidden, `is-hidden-${num + 1}`);
49-
structureField(select, `property-label-${num + 1}`);
50-
structureField(textareaValue, `property-value-${num + 1}`);
51-
structureField(textareaUri, `property-uri-${num + 1}`);
52-
structureField(innerClass, `inner-class-${num + 1}`);
53-
structureField(innerProperty, `inner-property-${num + 1}`);
54-
5572
container.find('.nested-data-type_repeat_property')
5673
.last()
5774
.find('.o-icon-private')
@@ -107,6 +124,7 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
107124
try {
108125
const properties = valueObj.properties;
109126
const keys = Object.keys(properties[0]);
127+
110128
keys.forEach((element, idx) => {
111129
let item = properties[0][element];
112130

@@ -135,24 +153,18 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
135153
}
136154

137155
else if (idx > 1) {
138-
cloneItem();
156+
cloneItem(idx);
139157
findItems();
140158

141159
container.find('.nested-data-type_hide_property').last().removeClass('o-icon-private').addClass('o-icon-public');
142160

143161
if (renderedLink) {
144162
renderedLink.remove();
145163
textareaValue.parent().parent().css('display', 'block');
146-
// textareaUri.parent().parent().css('display', 'block')
147164
}
148165

149-
structureField(isHidden, `is-hidden-${idx}`);
150-
structureField(textareaValue, `property-value-${idx}`);
151-
structureField(textareaUri, `property-uri-${idx}`);
152166
structureField(select, `property-label-${idx}`, insertVal = element);
153-
structureField(innerClass, `inner-class-${idx}`);
154167
innerClass.parent().css('display', 'none');
155-
structureField(innerProperty, `inner-property-${idx}`);
156168

157169
if (val['is_hidden']) {
158170
structureField(isHidden, `is-hidden-${idx}`, insertVal = 'true');
@@ -200,12 +212,10 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
200212
.last()
201213
.find('.input')
202214
.css('display', 'none');
203-
204-
structureInnerLinks(val[key]['label'], val['@id'].replace('/api/items/', '/admin/item/'));
215+
structureInnerLinks(val[key]['label'], val[key]['@id'].replace('/api/items/', '/admin/item/'));
205216
}
206217
}
207218
else if (idx > 1 && key != "is_hidden") {
208-
209219
structureField(innerProperty, `inner-property-${idx}`, insertVal = key);
210220
if (key == '@type') { structureField(innerClass, `inner-class-${idx}`, insertVal = value); };
211221
if (val[key]['@value']) { structureField(textareaValue, `property-value-${idx}`, insertVal = val[key]['@value']); }
@@ -245,21 +255,16 @@ $(document).on('o:prepare-value', function (e, type, value, valueObj) {
245255
if (thisValue.is('.selecting-resource')) {
246256
const num = container.find('.nested-data-type_repeat_property').length;
247257

248-
cloneItem();
258+
cloneItem(num + 1);
249259
findItems();
250260

251261
if (renderedLink) {
252262
renderedLink.remove();
253263
textareaValue.parent().parent().css('display', 'block');
254-
// textareaUri.parent().parent().css('display', 'block')
255264
}
256265

257-
structureField(isHidden, `is-hidden-${num + 1}`);
258-
structureField(select, `property-label-${num + 1}`);
259266
structureField(textareaValue, `property-value-${num + 1}`, insertVal = label);
260267
structureField(textareaUri, `property-uri-${num + 1}`, insertVal = id);
261-
structureField(innerClass, `inner-class-${num + 1}`);
262-
structureField(innerProperty, `inner-property-${num + 1}`);
263268

264269
container.find('.nested-data-type_repeat_property')
265270
.last()

config/module.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ name = "Nested Data Types"
33
description= "Allow users to choose a specific resource class as datatype, and inner properties."
44
author = "Giacomo Nanni"
55
author_link = "https://github.com/sinanatra"
6-
version = "3.2.1"
6+
version = "3.2.2"
77
omeka_version_constraint = "^3.0.0"

view/nested-data-type/data-type/nested-data-type.phtml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@
33
<input type="hidden" class="nested-data-type_value" data-value-key="@value"/>
44

55
<div class="nested-data-type_properties">
6+
<datalist id="property-dropdown" name="property-dropdown">
7+
<?php foreach($properties as $property): ?>
8+
<option value="<?= $property->term() ?>"><?= $property->label() ?></option>
9+
<?php endforeach; ?>
10+
</datalist>
11+
<datalist id="class-dropdown" name="class-dropdown">
12+
<?php foreach($classes as $class): ?>
13+
<option value="<?= $class->term() ?>"><?= $class->label() ?></option>
14+
<?php endforeach; ?>
15+
</datalist>
616
<div class="nested-data-type_repeat_property">
717
<div class="nested-data-type_repeat_property_list">
818
<input class="nested-data-type-dropwdown nested-data-type_property_dropdown" list="property-dropdown" data-value-key="property-label-1" placeholder="Select a property" />
9-
<datalist id="property-dropdown" name="property-dropdown">
10-
<?php foreach($properties as $property): ?>
11-
<option value="<?= $property->term() ?>"><?= $property->label() ?></option>
12-
<?php endforeach; ?>
13-
</datalist>
1419
<button class="nested-data-type_button o-icon-add nested-data-type_add_class"></button>
1520
</div>
1621
<div class="nested-data-type_repeat_class hidden">
1722
<input class="nested-data-type-dropwdown inner-class" list="class-dropdown" data-value-key="inner-class-1" placeholder="Select a class" />
18-
<datalist id="class-dropdown" name="class-dropdown">
19-
<?php foreach($classes as $class): ?>
20-
<option value="<?= $class->term() ?>"><?= $class->label() ?></option>
21-
<?php endforeach; ?>
22-
</datalist>
23-
<input class="nested-data-type-dropwdown inner-property" list="property-dropdown" data-value-key="inner-property-1" placeholder="Select a property" />
23+
<input class="nested-data-type-dropwdown inner-property" list="property-dropdown" data-value-key="inner-property-1" placeholder="Select a property" />
2424
</div>
25-
2625
<div class="input">
2726
<label class="value">
2827
<textarea class="property-value" name="property-value" data-value-key="property-value-1"></textarea>

0 commit comments

Comments
 (0)