Skip to content

Commit 20e23ec

Browse files
committed
version 0.4.3
1 parent c7e7283 commit 20e23ec

8 files changed

+87
-15
lines changed

changelog.json

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
[
2+
{
3+
"version": "0.4.3",
4+
"downloadUrl": "https://github.com/engram-design/SuperTable/archive/0.4.3.zip",
5+
"date": "2016-02-28 18:15:00",
6+
"notes": [
7+
"[Fixed] Fixed issue with JS not firing correctly in field settings - caused some field types to not allow editing of settings.",
8+
"[Fixed] Fixed issue where blocks were being overwritten when entries are saved as drafts.",
9+
"[Improved] You now have direct access to fields when using the Static Field option. No more looping or using `superTableField[0].fieldHandle`."
10+
]
11+
},
212
{
313
"version": "0.4.2",
414
"downloadUrl": "https://github.com/engram-design/SuperTable/archive/0.4.2.zip",

supertable/SuperTablePlugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function getName()
1414

1515
public function getVersion()
1616
{
17-
return '0.4.2';
17+
return '0.4.3';
1818
}
1919

2020
public function getSchemaVersion()

supertable/fieldtypes/SuperTableFieldType.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,30 @@ public function prepValue($value)
172172
}
173173
}
174174

175-
return $criteria;
175+
if ($this->settings->staticField) {
176+
return $criteria[0];
177+
} else {
178+
return $criteria;
179+
}
180+
}
181+
182+
public function modifyElementsQuery(DbCommand $query, $value)
183+
{
184+
if ($value == 'not :empty:') {
185+
$value = ':notempty:';
186+
}
187+
188+
if ($value == ':notempty:' || $value == ':empty:') {
189+
$alias = 'supertableblocks_'.$this->model->handle;
190+
$operator = ($value == ':notempty:' ? '!=' : '=');
191+
192+
$query->andWhere(
193+
"(select count({$alias}.id) from {{supertableblocks}} {$alias} where {$alias}.ownerId = elements.id and {$alias}.fieldId = :fieldId) {$operator} 0",
194+
array(':fieldId' => $this->model->id)
195+
);
196+
} else if ($value !== null) {
197+
return false;
198+
}
176199
}
177200

178201
public function getInputHtml($name, $value)
@@ -450,6 +473,7 @@ private function _getBlockTypeInfoForInput($name)
450473

451474
if ($this->element) {
452475
$block->setOwner($this->element);
476+
$block->locale = $this->element->locale;
453477
}
454478

455479
$fieldLayoutFields = $blockType->getFieldLayout()->getFields();

supertable/resources/js/SuperTableConfigurator.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,6 @@ Craft.SuperTableSettingsModal = Garnish.Modal.extend({
274274

275275
this.$fieldSettings = this.$settingsContainer.appendTo($main);
276276

277-
// Give the modal window some time to get it together
278-
setTimeout($.proxy(function() {
279-
Craft.initUiElements(this.$fieldSettings);
280-
Garnish.$bod.append(this.fieldTypeFootHtml);
281-
}, this), 1);
282-
283277
this.addListener(this.$closeBtn, 'activate', 'closeModal');
284278
},
285279

@@ -305,6 +299,14 @@ Craft.SuperTableSettingsModal = Garnish.Modal.extend({
305299
this.removeListener(this.$saveBtn, 'click');
306300
},
307301

302+
onFadeIn: function() {
303+
// Give the modal window some time to get it together
304+
setTimeout($.proxy(function() {
305+
Craft.initUiElements(this.$fieldSettings);
306+
Garnish.$bod.append(this.fieldTypeFootHtml);
307+
}, this), 1);
308+
},
309+
308310
closeModal: function() {
309311
this.hide();
310312
},

supertable/resources/js/SuperTableInput.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ Craft.SuperTableInputTable = Garnish.Base.extend({
4141

4242
for (var i = 0; i < $rows.length; i++) {
4343
new Craft.EditableTable.Row(this, $rows[i]);
44+
45+
var $block = $($rows[i]),
46+
id = $block.data('id');
47+
48+
// Is this a new block?
49+
var newMatch = (typeof id == 'string' && id.match(/new(\d+)/));
50+
51+
if (newMatch && newMatch[1] > this.totalNewBlocks) {
52+
this.totalNewBlocks = parseInt(newMatch[1]);
53+
}
4454
}
4555

4656
this.updateAddBlockBtn();
@@ -153,6 +163,16 @@ Craft.SuperTableInputRow = Garnish.Base.extend({
153163

154164
for (var i = 0; i < this.$rows.length; i++) {
155165
new Craft.SuperTableInputRow.Row(this, this.$rows[i]);
166+
167+
var $block = $(this.$rows[i]),
168+
id = $block.data('id');
169+
170+
// Is this a new block?
171+
var newMatch = (typeof id == 'string' && id.match(/new(\d+)/));
172+
173+
if (newMatch && newMatch[1] > this.totalNewBlocks) {
174+
this.totalNewBlocks = parseInt(newMatch[1]);
175+
}
156176
}
157177

158178
this.$addRowBtn = this.$divInner.next('.add');
@@ -178,7 +198,7 @@ Craft.SuperTableInputRow = Garnish.Base.extend({
178198

179199
var staticFieldStyle = (this.settings.staticField) ? 'style="display: none;"' : '';
180200

181-
var html = '<div class="superTableRow">' +
201+
var html = '<div class="superTableRow" data-id="'+id+'">' +
182202
'<input type="hidden" name="'+this.inputNamePrefix+'['+id+'][type]" value="'+type+'">' +
183203
'<table id="'+id+'" class="shadow-box editable superTable">' +
184204
'<tbody>' +

supertable/services/SuperTableService.php

+8
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ public function deleteBlockType(SuperTable_BlockTypeModel $blockType)
262262

263263
$this->deleteBlockById($blockIds);
264264

265+
// Set the new contentTable
266+
$originalContentTable = craft()->content->contentTable;
267+
$superTableField = craft()->fields->getFieldById($blockType->fieldId);
268+
$newContentTable = $this->getContentTableName($superTableField);
269+
craft()->content->contentTable = $newContentTable;
270+
265271
// Now delete the block type fields
266272
$originalFieldColumnPrefix = craft()->content->fieldColumnPrefix;
267273
craft()->content->fieldColumnPrefix = 'field_';
@@ -270,7 +276,9 @@ public function deleteBlockType(SuperTable_BlockTypeModel $blockType)
270276
craft()->fields->deleteField($field);
271277
}
272278

279+
// Restore the contentTable and the fieldColumnPrefix to original values.
273280
craft()->content->fieldColumnPrefix = $originalFieldColumnPrefix;
281+
craft()->content->contentTable = $newContentTable;
274282

275283
// Delete the field layout
276284
craft()->fields->deleteLayoutById($blockType->fieldLayoutId);

supertable/templates/rowInput.html

+10-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
<div class="rowLayoutContainer">
99
{% set totalNewBlocks = 0 %}
1010

11+
{% if settings.staticField %}
12+
{% set blocks = [blocks] %}
13+
{% endif %}
14+
1115
{% for block in blocks %}
12-
<div class="superTableRow">
13-
{% set blockId = block.id %}
16+
{% set blockId = block.id %}
1417

15-
{% if not blockId %}
16-
{% set totalNewBlocks = totalNewBlocks + 1 %}
17-
{% set blockId = 'new'~totalNewBlocks %}
18-
{% endif %}
18+
{% if not blockId %}
19+
{% set totalNewBlocks = totalNewBlocks + 1 %}
20+
{% set blockId = 'new'~totalNewBlocks %}
21+
{% endif %}
1922

23+
<div class="superTableRow" data-id="{{ blockId }}">
2024
<input type="hidden" name="{{ name }}[{{ blockId }}][type]" value="{{ block.getType() }}">
2125

2226
<table class="shadow-box editable superTable">

supertable/templates/tableInput.html

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
</thead>
2525
<tbody>
2626
{% set totalNewBlocks = 0 %}
27+
28+
{% if settings.staticField %}
29+
{% set blocks = [blocks] %}
30+
{% endif %}
2731

2832
{% for block in blocks %}
2933
{% set blockId = block.id %}

0 commit comments

Comments
 (0)