Skip to content

Commit

Permalink
version 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Jun 13, 2016
1 parent 52bba83 commit 45d166e
Show file tree
Hide file tree
Showing 10 changed files with 457 additions and 543 deletions.
18 changes: 18 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
[
{
"version": "1.5.0",
"downloadUrl": "https://github.com/engram-design/FieldManager/archive/1.5.0.zip",
"date": "2016-06-14T22:40:00+10:00",
"notes": [
"[Added] Added clone, import/export support for Matrix > SuperTable > Matrix field configuration (phew!).",
"[Improved] Changed export/import structure for better consistency, readability and for Matrix/SuperTable support. Supports older exports with deprecation notice.",
"[Improved] Allow `metaKey` (cmd+click) functionality. Thanks to [@timkelty](https://github.com/timkelty)",
"[Improved] Refactored cloning logic for all fields (now much simpler)",
"[Improved] Better logging and UI feedback for various tasks",
"[Improved] Better clone, import/export support for Matrix-SuperTable combination",
"[Improved] Better logging and flow for import - doesn't die so much when things go wrong",
"[Fixed] Fix issue for Matrix and SuperTable fields not being created properly on import/clone.",
"[Fixed] Fix where field modals disappeared when failing validation.",
"[Fixed] Fix for reordering dropdown fields (and other option fields) and not persisting order.",
"[Fixed] Fix field options not updating when changing field type."
]
},
{
"version": "1.4.5",
"downloadUrl": "https://github.com/engram-design/FieldManager/archive/1.4.5.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.5';
return '1.5.0';
}

public function getSchemaVersion()
Expand Down
144 changes: 79 additions & 65 deletions fieldmanager/controllers/FieldManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function actionGetGroupFieldHtml()

$variables = array(
'group' => $group,
'prefix' => craft()->fieldManager->generateHandle($group->name) . '_',
'prefix' => StringHelper::toCamelCase($group->name) . '_',
);

$returnData['html'] = $this->renderTemplate('fieldmanager/_group/' . $template, $variables, true);
Expand All @@ -30,36 +30,18 @@ public function actionMapFields()
$this->requirePostRequest();

$json = craft()->request->getParam('data', '{}');
$data = json_decode($json, true);
$data = craft()->fieldManager_import->getData($json);

if ($data !== null) {
if ($data) {
$this->renderTemplate('fieldmanager/import/map', array(
'fields' => $data,
'fields' => $data,
'errors' => array(),
));
} else {
craft()->userSession->setError(Craft::t('Could not parse JSON data.'));
}

}

/*public function actionGetSingleFieldHtml()
{
$this->requirePostRequest();
$this->requireAjaxRequest();
$fieldId = craft()->request->getRequiredPost('fieldId');
$groupId = craft()->request->getRequiredPost('groupId');
$variables = array(
'field' => craft()->fields->getFieldById($fieldId),
'group' => craft()->fields->getGroupById($groupId),
);
$returnData['html'] = $this->renderTemplate('fieldmanager/_single/single', $variables, true);
$this->returnJson($returnData);
}*/

public function actionGetModalBody()
{
$this->requirePostRequest();
Expand Down Expand Up @@ -87,54 +69,53 @@ public function actionGetModalBody()
$this->returnJson($returnData);
}


public function actionSaveSingleField()
public function actionCloneField()
{
$this->requirePostRequest();
$this->requireAjaxRequest();

$settings = array(
'fieldId' => craft()->request->getPost('fieldId'),
'group' => craft()->request->getRequiredPost('group'),
'name' => craft()->request->getPost('name'),
'handle' => craft()->request->getPost('handle'),
'instructions' => craft()->request->getPost('instructions'),
'translatable' => (bool)craft()->request->getPost('translatable'),
'type' => craft()->request->getRequiredPost('type'),
'types' => craft()->request->getPost('types'),
);
$fieldId = craft()->request->getRequiredPost('fieldId');

$originField = craft()->fields->getFieldById($settings['fieldId']);
$field = new FieldModel();
$field->groupId = craft()->request->getRequiredPost('group');
$field->name = craft()->request->getPost('name');
$field->handle = craft()->request->getPost('handle');
$field->instructions = craft()->request->getPost('instructions');
$field->translatable = (bool)craft()->request->getPost('translatable');
$field->type = craft()->request->getRequiredPost('type');

$typeSettings = craft()->request->getPost('types');
if (isset($typeSettings[$field->type])) {
$field->settings = $typeSettings[$field->type];
}

$returnData = craft()->fieldManager->saveField($settings, false);
$originField = craft()->fields->getFieldById($fieldId);

$this->returnJson($returnData);
if (craft()->fieldManager->saveField($field, $originField)) {
$this->returnJson(array('success' => true, 'fieldId' => $field->id));
} else {
$this->returnJson(array('success' => false, 'error' => $field->getErrors()));
}
}

public function actionSaveGroupField()
public function actionCloneGroup()
{
$this->requirePostRequest();
$this->requireAjaxRequest();

$settings = array(
'groupId' => craft()->request->getRequiredPost('groupId'),
'name' => craft()->request->getRequiredPost('name'),
'prefix' => craft()->request->getRequiredPost('prefix'),
);
$groupId = craft()->request->getRequiredPost('groupId');
$prefix = craft()->request->getRequiredPost('prefix');

$originGroup = craft()->fields->getGroupById($settings['groupId']);
$group = new FieldGroupModel();
$group->name = craft()->request->getRequiredPost('name');

if ((craft()->fieldManager->saveGroup($settings)) !== false) {
$returnData = array('success' => true);
$originGroup = craft()->fields->getGroupById($groupId);

craft()->userSession->setNotice(Craft::t($originGroup->name . ' field group cloned successfully.'));
if (craft()->fieldManager->saveGroup($group, $prefix, $originGroup)) {
$this->returnJson(array('success' => true, 'groupId' => $group->id));
} else {
$returnData = array('success' => false);

//craft()->userSession->setError(Craft::t('Could not clone the '.$originGroup->name.' field group.'));
$this->returnJson(array('success' => false, 'error' => $group->getErrors()));
}

$this->returnJson($returnData);
}

public function actionExport()
Expand All @@ -160,35 +141,68 @@ public function actionImport()

$fields = craft()->request->getParam('fields', '');
$json = craft()->request->getParam('data', '{}');
$data = json_decode($json, true);
$data = craft()->fieldManager_import->getData($json);

// First - remove any field we're not importing
$fieldsToImport = array();
foreach ($fields as $key => $field) {
if ($field['groupId'] != 'noimport') {

// Get the field data from our imported JSON data
$fieldsToImport[$field['handle']] = $data[$field['origHandle']];
if (isset($field['groupId'])) {
if ($field['groupId'] != 'noimport') {

// But then remove the Name value - the user may have changed this!
$fieldsToImport[$field['handle']]['name'] = $field['name'];
// Get the field data from our imported JSON data
$fieldsToImport[$key] = $data[$key];

// Then add the Group ID
$fieldsToImport[$field['handle']]['groupId'] = $field['groupId'];
$fieldsToImport[$key]['name'] = $field['name'];
$fieldsToImport[$key]['handle'] = $field['handle'];
$fieldsToImport[$key]['groupId'] = $field['groupId'];
}
}
}

if (count($fieldsToImport) > 0) {
$fieldImportResult = craft()->fieldManager_import->import($fieldsToImport);
$importErrors = craft()->fieldManager_import->import($fieldsToImport);

if ($fieldImportResult === true) {
if (!$importErrors) {
craft()->userSession->setNotice('Imported successfully.');
} else {
craft()->userSession->setError(implode(', ', $fieldImportResult));
craft()->userSession->setError('Error importing fields.');

$this->renderTemplate('fieldmanager/import/map', array(
'fields' => $fieldsToImport,
'errors' => $importErrors,
));
}
} else {
craft()->userSession->setNotice('No fields imported.');
}
}

// From Craft's native saveField, which doesn't really support Ajax...
public function actionSaveField()
{
$this->requirePostRequest();

$field = new FieldModel();

$field->id = craft()->request->getPost('fieldId');
$field->groupId = craft()->request->getRequiredPost('group');
$field->name = craft()->request->getPost('name');
$field->handle = craft()->request->getPost('handle');
$field->instructions = craft()->request->getPost('instructions');
$field->translatable = (bool) craft()->request->getPost('translatable');

$field->type = craft()->request->getRequiredPost('type');

$typeSettings = craft()->request->getPost('types');
if (isset($typeSettings[$field->type])) {
$field->settings = $typeSettings[$field->type];
}

if (craft()->fields->saveField($field)) {
$this->returnJson(array('success' => true));
} else {
$this->returnJson(array('success' => false, 'error' => $field->getErrors()));
}
}

}
19 changes: 17 additions & 2 deletions fieldmanager/resources/css/fieldmanager.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,33 @@ body.ltr .rightalign {
}



#fieldmapping {
width: auto;
table-layout: fixed;
}

#fieldmapping thead tr th {
vertical-align: middle;
border: none;
}

#fieldmapping tbody tr td {
text-align: left;
}

#fieldmapping tbody tr td.textarea {
padding-left: 0;
padding: 4px 10px !important;
vertical-align: top;
}

#fieldmapping tbody tr td.textarea.has-error textarea {
border: 1px solid #da5a47 !important;
}

#fieldmapping tbody tr td.textarea.has-error .errors {
color: #da5a47;
padding: 5px 10px 2px;
display: block;
}

#fieldmapping textarea {
Expand Down
Loading

0 comments on commit 45d166e

Please sign in to comment.