Skip to content

Commit

Permalink
version 1.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Feb 21, 2016
1 parent 269c694 commit 859e30c
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 52 deletions.
12 changes: 12 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
[
{
"version": "1.4.3",
"downloadUrl": "https://github.com/engram-design/FieldManager/archive/1.4.3.zip",
"date": "2016-02-21 18:20:00",
"notes": [
"[Added] Create new fields directly from the Field Manager page [#16](https://github.com/engram-design/FieldManager/issues/16).",
"[Added] Fields are shown if they are unused - handy to keep your fields clean [#16](https://github.com/engram-design/FieldManager/issues/16).",
"[Fixed] Fixed issue when cloning Matrix field and not carrying over instructions [#17](https://github.com/engram-design/FieldManager/issues/17).",
"[Fixed] Instructions were missing when importing/exporting Matrix & Super Table field.",
"[Fixed] Additional fixes for Matrix/Super Table nested cloning and importing."
]
},
{
"version": "1.4.2",
"downloadUrl": "https://github.com/engram-design/FieldManager/archive/1.4.2.zip",
Expand Down
2 changes: 1 addition & 1 deletion fieldmanager/FieldManagerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getName()

public function getVersion()
{
return '1.4.2';
return '1.4.3';
}

public function getSchemaVersion()
Expand Down
19 changes: 12 additions & 7 deletions fieldmanager/controllers/FieldManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,21 @@ public function actionGetModalBody()
$this->requirePostRequest();
$this->requireAjaxRequest();

$fieldId = craft()->request->getRequiredPost('fieldId');
$groupId = craft()->request->getRequiredPost('groupId');
$template = craft()->request->getRequiredPost('template');
$fieldId = craft()->request->getPost('fieldId');
$groupId = craft()->request->getPost('groupId');
$template = craft()->request->getPost('template');

$field = craft()->fields->getFieldById($fieldId);

$variables = array(
'field' => craft()->fields->getFieldById($fieldId),
'group' => craft()->fields->getGroupById($groupId),
);
$variables = array();

if ($fieldId) {
$variables['field'] = craft()->fields->getFieldById($fieldId);
}

if ($groupId) {
$variables['group'] = craft()->fields->getGroupById($groupId);
}

// Don't process the output yet - issues with JS in template...
$returnData = $this->renderTemplate('fieldmanager/_single/'.$template, $variables, false, false);
Expand Down
8 changes: 5 additions & 3 deletions fieldmanager/resources/css/fieldmanager.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ body.ltr .rightalign {
color: rgba(0, 0, 0, 0.2);
}




.unused-field {
color: #e78640;
font-size: 11px;
margin-left: 5px;
}



Expand Down
107 changes: 104 additions & 3 deletions fieldmanager/resources/js/fieldmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,21 @@ $(function() {
new Craft.SingleFieldSettingsModal($(this), $(this).parents('tr.field'));
});

$('tr.group a.go').on('click', function(e) {
$('tr.group .go a').on('click', function(e) {
e.preventDefault();
new Craft.FieldManagerEditGroupField($(this), $(this).parents('tr.group'));
});

$('tr.field a.go').on('click', function(e) {
$('tr.field .go a').on('click', function(e) {
e.preventDefault();
new Craft.SingleFieldEditModal($(this), $(this).parents('tr.field'));
});

$('.new-field-btn').on('click', function(e) {
e.preventDefault();
new Craft.SingleFieldAddModal($(this));
});


// Handle deleting field group seperately
$('.delete-group').on('click', function(e) {
Expand Down Expand Up @@ -482,7 +487,12 @@ $(function() {
this.$footerSpinner = $('<div class="spinner hidden"/>').appendTo($footer);
this.$buttons = $('<div class="buttons rightalign first"/>').appendTo($footer);
this.$cancelBtn = $('<div class="btn">'+Craft.t('Cancel')+'</div>').appendTo(this.$buttons);
this.$saveBtn = $('<div class="btn submit">'+Craft.t('Clone')+'</div>').appendTo(this.$buttons);

if (!this.fieldId) {
this.$saveBtn = $('<div class="btn submit">'+Craft.t('Add field')+'</div>').appendTo(this.$buttons);
} else {
this.$saveBtn = $('<div class="btn submit">'+Craft.t('Clone')+'</div>').appendTo(this.$buttons);
}

this.$body = $body;

Expand Down Expand Up @@ -562,6 +572,8 @@ $(function() {





Craft.SingleFieldEditModal = Garnish.Modal.extend({
fieldId: null,
groupId: null,
Expand Down Expand Up @@ -653,6 +665,95 @@ $(function() {



Craft.SingleFieldAddModal = Garnish.Modal.extend({
fieldId: null,
groupId: null,

$body: null,
$element: null,
$buttons: null,
$cancelBtn: null,
$saveBtn: null,
$footerSpinner: null,

init: function($element, $data) {
this.$element = $element;

// Build the modal
var $container = $('<div class="modal fieldsettingsmodal"></div>').appendTo(Garnish.$bod),
$body = $('<div class="body"><div class="spinner big"></div></div>').appendTo($container),
$footer = $('<div class="footer"/>').appendTo($container);

this.base($container, this.settings);

this.$footerSpinner = $('<div class="spinner hidden"/>').appendTo($footer);
this.$buttons = $('<div class="buttons rightalign first"/>').appendTo($footer);
this.$cancelBtn = $('<div class="btn">'+Craft.t('Cancel')+'</div>').appendTo(this.$buttons);
this.$saveBtn = $('<div class="btn submit">'+Craft.t('Save')+'</div>').appendTo(this.$buttons);

this.$body = $body;

this.addListener(this.$cancelBtn, 'activate', 'onFadeOut');
this.addListener(this.$saveBtn, 'activate', 'saveSettings');
},

onFadeIn: function() {
var data = {
template: 'modal_edit',
};

Craft.postActionRequest('fieldManager/getModalBody', data, $.proxy(function(response, textStatus) {
if (textStatus == 'success') {
this.$body.html(response);

Craft.initUiElements(this.$body);

new Craft.HandleGenerator('#name', '#handle');
}
}, this));

this.base();
},

onFadeOut: function() {
this.hide();
this.destroy();
this.$shade.remove();
this.$container.remove();

this.removeListener(this.$saveBtn, 'click');
this.removeListener(this.$cancelBtn, 'click');
},

saveSettings: function() {
var params = this.$body.find('form').serializeObject();
params.fieldId = this.fieldId;

this.$footerSpinner.removeClass('hidden');

Craft.postActionRequest('fields/saveField', params, $.proxy(function(response, textStatus) {
this.$footerSpinner.addClass('hidden');

this.onFadeOut();
Craft.cp.displayNotice(Craft.t('Field added.'));

location.href = Craft.getUrl('fieldmanager');

}, this));

this.removeListener(this.$saveBtn, 'click');
this.removeListener(this.$cancelBtn, 'click');
},

show: function() {
this.base();
},
});






});

Expand Down
55 changes: 51 additions & 4 deletions fieldmanager/services/FieldManagerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function processMatrix($originField, $field) {
$blockTypes = craft()->matrix->getBlockTypesByFieldId($originField->id);

$newBlockTypes = array();
$extraFields = array();
foreach ($blockTypes as $originBlockType) {
$newBlockType = new MatrixBlockTypeModel();

Expand All @@ -142,11 +143,16 @@ public function processMatrix($originField, $field) {
$newBlockField->name = $originField->name;
$newBlockField->handle = $originField->handle;
$newBlockField->required = $originField->required;
$newBlockField->instructions = $originField->instructions;
$newBlockField->translatable = $originField->translatable;
$newBlockField->type = $originField->type;
$newBlockField->settings = $originField->settings;

$newBlockFields[] = $newBlockField;

if ($newBlockField->type == 'SuperTable') {
$extraFields[] = array($originField, $newBlockField);
}
}

$newBlockType->setFields($newBlockFields);
Expand All @@ -155,8 +161,14 @@ public function processMatrix($originField, $field) {
$newBlockTypes[] = $newBlockType;
}

$settings->setBlockTypes($newBlockTypes);
craft()->matrix->saveSettings($settings);
//$settings->setBlockTypes($newBlockTypes);
//craft()->matrix->saveSettings($settings);

if ($extraFields) {
foreach ($extraFields as $options) {
$this->processSuperTable($options[0], $options[1]);
}
}
}

public function processSuperTable($originField, $field) {
Expand All @@ -166,6 +178,7 @@ public function processSuperTable($originField, $field) {
$blockTypes = craft()->superTable->getBlockTypesByFieldId($originField->id);

$newBlockTypes = array();
$extraFields = array();
foreach ($blockTypes as $originBlockType) {
$newBlockType = new SuperTable_BlockTypeModel();

Expand All @@ -180,11 +193,16 @@ public function processSuperTable($originField, $field) {
$newBlockField->name = $originField->name;
$newBlockField->handle = $originField->handle;
$newBlockField->required = $originField->required;
$newBlockField->instructions = $originField->instructions;
$newBlockField->translatable = $originField->translatable;
$newBlockField->type = $originField->type;
$newBlockField->settings = $originField->settings;

$newBlockFields[] = $newBlockField;

if ($newBlockField->type == 'Matrix') {
$extraFields[] = array($originField, $newBlockField);
}
}

$newBlockType->setFields($newBlockFields);
Expand All @@ -193,8 +211,37 @@ public function processSuperTable($originField, $field) {
$newBlockTypes[] = $newBlockType;
}

$settings->setBlockTypes($newBlockTypes);
craft()->superTable->saveSettings($settings);
//$settings->setBlockTypes($newBlockTypes);
//craft()->superTable->saveSettings($settings);

if ($extraFields) {
foreach ($extraFields as $options) {
$this->processMatrix($options[0], $options[1]);
}
}
}

public function getUnusedFieldIds()
{
// All fields
$query = craft()->db->createCommand();
$allFieldIds = $query
->select('craft_fields.id')
->from('fields')
->order('craft_fields.id')
->queryColumn();

// Fields in-use
$query = craft()->db->createCommand();
$query->distinct = true;
$usedFieldIds = $query
->select('craft_fieldlayoutfields.fieldId')
->from('fieldlayoutfields')
->order('craft_fieldlayoutfields.fieldId')
->queryColumn();

// Get only the unused fields
return array_diff($allFieldIds, $usedFieldIds);
}


Expand Down
2 changes: 2 additions & 0 deletions fieldmanager/services/FieldManager_ExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function handleMatrixExport($field)
$blockTypeFieldDefs[$blockTypeField->handle] = array(
'name' => $blockTypeField->name,
'required' => $blockTypeField->required,
'instructions' => $blockTypeField->instructions,
'translatable' => $blockTypeField->translatable,
'type' => $blockTypeField->type,
'settings' => $blockTypeField->settings
Expand Down Expand Up @@ -79,6 +80,7 @@ public function handleSuperTableExport($field)
$blockTypeFieldDefs[$blockTypeField->handle] = array(
'name' => $blockTypeField->name,
'required' => $blockTypeField->required,
'instructions' => $blockTypeField->instructions,
'translatable' => $blockTypeField->translatable,
'type' => $blockTypeField->type,
'settings' => $blockTypeField->settings
Expand Down
24 changes: 16 additions & 8 deletions fieldmanager/services/FieldManager_ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function handleMatrixImport($fieldDef, $field)
$blockTypeField->name = $blockTypeFieldDef['name'];
$blockTypeField->handle = $blockTypeFieldHandle;
$blockTypeField->required = $blockTypeFieldDef['required'];
$blockTypeField->instructions = isset($blockTypeFieldDef['instructions']) ? $blockTypeFieldDef['instructions'] : '';
$blockTypeField->translatable = $blockTypeFieldDef['translatable'];
$blockTypeField->type = $blockTypeFieldDef['type'];
$blockTypeField->settings = $blockTypeFieldDef['settings'];
Expand All @@ -98,11 +99,14 @@ public function handleMatrixImport($fieldDef, $field)
$blockType->setFields($newBlockTypeFields);

craft()->matrix->saveBlockType($blockType);
$settings->setBlockTypes(array($blockType));
$success = craft()->matrix->saveSettings($settings);

foreach ($extraFields as $options) {
$this->handleSuperTableImport($options[0], $options[1]);
if ($extraFields) {
//$settings->setBlockTypes(array($blockType));
//$success = craft()->matrix->saveSettings($settings);

foreach ($extraFields as $options) {
$this->handleSuperTableImport($options[0], $options[1]);
}
}
}
}
Expand All @@ -124,6 +128,7 @@ public function handleSuperTableImport($fieldDef, $field)
$blockTypeField->name = $blockTypeFieldDef['name'];
$blockTypeField->handle = $blockTypeFieldHandle;
$blockTypeField->required = $blockTypeFieldDef['required'];
$blockTypeField->instructions = isset($blockTypeFieldDef['instructions']) ? $blockTypeFieldDef['instructions'] : '';
$blockTypeField->translatable = $blockTypeFieldDef['translatable'];
$blockTypeField->type = $blockTypeFieldDef['type'];
$blockTypeField->settings = $blockTypeFieldDef['settings'];
Expand All @@ -142,11 +147,14 @@ public function handleSuperTableImport($fieldDef, $field)
$blockType->setFields($newBlockTypeFields);

craft()->superTable->saveBlockType($blockType);
$settings->setBlockTypes(array($blockType));
$success = craft()->superTable->saveSettings($settings);

foreach ($extraFields as $options) {
$this->handleMatrixImport($options[0], $options[1]);
if ($extraFields) {
//$settings->setBlockTypes(array($blockType));
//$success = craft()->superTable->saveSettings($settings);

foreach ($extraFields as $options) {
$this->handleMatrixImport($options[0], $options[1]);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fieldmanager/templates/_single/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
id: 'group',
name: 'group',
options: groupOptions,
value: group.id,
value: (group is defined ? group.id : null),
}) }}

{{ forms.textField({
Expand Down
Loading

0 comments on commit 859e30c

Please sign in to comment.