Skip to content

Commit c4f092e

Browse files
committed
initial commit
Signed-off-by: Josh Crawford <[email protected]>
1 parent 199515b commit c4f092e

33 files changed

+1745
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
supertable-matrix

supertable/SuperTablePlugin.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Craft;
3+
4+
class SuperTablePlugin extends BasePlugin
5+
{
6+
/* --------------------------------------------------------------
7+
* PLUGIN INFO
8+
* ------------------------------------------------------------ */
9+
10+
public function getName()
11+
{
12+
return Craft::t('Super Table');
13+
}
14+
15+
public function getVersion()
16+
{
17+
return '1.0';
18+
}
19+
20+
public function getDeveloper()
21+
{
22+
return 'S. Group';
23+
}
24+
25+
public function getDeveloperUrl()
26+
{
27+
return 'http://sgroup.com.au';
28+
}
29+
30+
31+
/* --------------------------------------------------------------
32+
* HOOKS
33+
* ------------------------------------------------------------ */
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
namespace Craft;
3+
4+
class SuperTableController extends BaseController
5+
{
6+
public function actionGetTableRow()
7+
{
8+
$this->requirePostRequest();
9+
$this->requireAjaxRequest();
10+
11+
$tableId = craft()->request->getRequiredPost('tableId');
12+
$rowId = craft()->request->getRequiredPost('rowId');
13+
$cols = craft()->request->getRequiredPost('cols');
14+
$name = craft()->request->getRequiredPost('name');
15+
16+
foreach ($cols as $colId => $col) {
17+
$field = craft()->superTable_table->getFieldById($tableId, $col['fieldId']);
18+
19+
$fieldtype = craft()->superTable_table->populateFieldType($tableId, $field);
20+
21+
$cols[$colId]['fieldType'] = $fieldtype;
22+
}
23+
24+
$variables = array(
25+
'tableId' => $tableId,
26+
'rowId' => $rowId,
27+
'cols' => $cols,
28+
'name' => $name,
29+
);
30+
31+
craft()->templates->startJsBuffer();
32+
$returnData['html'] = $this->renderTemplate('supertable/row', $variables, true);
33+
$returnData['js'] = craft()->templates->clearJsBuffer();
34+
35+
$this->returnJson($returnData);
36+
}
37+
38+
public function actionGetModalBody()
39+
{
40+
$this->requirePostRequest();
41+
$this->requireAjaxRequest();
42+
43+
$fieldId = craft()->request->getPost('fieldId');
44+
$tableId = craft()->request->getPost('tableId');
45+
$fieldType = craft()->request->getPost('fieldType');
46+
47+
// If there isn't a field yet, this is a brand-new row thats been added
48+
if ($fieldId) {
49+
50+
// Get the field
51+
$field = craft()->superTable_table->getFieldById($tableId, $fieldId);
52+
53+
// Get the fieldtype for this field
54+
$fieldtype = craft()->superTable_table->getFieldtypeForField($field);
55+
56+
// Grab the fieldtypes Settings in HTML - complete with populated settings
57+
$fieldtype->setSettings($field->settings);
58+
} else {
59+
60+
// No field yet - get default
61+
$fieldtype = craft()->fields->getFieldType($fieldType);
62+
}
63+
64+
$variables = array(
65+
'fieldType' => $fieldtype,
66+
);
67+
68+
// Don't process the output yet - issues with JS in template...
69+
$returnData = $this->renderTemplate('supertable/settings/modal', $variables, false, false);
70+
71+
$this->returnJson($returnData);
72+
}
73+
74+
public function actionSetSettingsFromModal()
75+
{
76+
$this->requirePostRequest();
77+
$this->requireAjaxRequest();
78+
79+
$fieldId = craft()->request->getRequiredPost('fieldId');
80+
$tableId = craft()->request->getRequiredPost('tableId');
81+
$settings = craft()->request->getRequiredPost('settings');
82+
83+
// Get the field
84+
$field = craft()->superTable_table->getFieldById($tableId, $fieldId);
85+
86+
$returnData = craft()->superTable_table->setFieldSettings($tableId, $field, $settings);
87+
88+
$this->returnJson($returnData);
89+
}
90+
91+
/*public function actionGetBlankField()
92+
{
93+
$this->requirePostRequest();
94+
$this->requireAjaxRequest();
95+
96+
//$fieldId = craft()->request->getRequiredPost('fieldId');
97+
//$tableId = craft()->request->getRequiredPost('tableId');
98+
//$settings = craft()->request->getRequiredPost('settings');
99+
100+
// Get the field
101+
//$field = craft()->superTable_table->getFieldById($tableId, $fieldId);
102+
103+
$field = craft()->superTable_table->getFieldById('224', '272');
104+
105+
//$fieldtype = craft()->superTable_table->getFieldtypeForField($field);
106+
107+
//$returnData = $fieldtype->getInputHtml('', '');
108+
109+
110+
111+
$variables = array(
112+
'col' => array(
113+
'name' => $field->name,
114+
'handle' => $field->handle,
115+
'type' => $field->type,
116+
'settings' => $field->settings,
117+
'fieldType' => $field->fieldtype,
118+
119+
120+
121+
),
122+
'value' => '',
123+
'cellName' => 'fields[superTable'.$field->type.'][row1][col2]',
124+
);
125+
126+
127+
128+
$returnData = $this->renderTemplate('supertable/_fields/categories', $variables, false, false);
129+
130+
131+
$this->returnJson($returnData);
132+
}
133+
134+
public function actionCreateSuperTable()
135+
{
136+
$this->requirePostRequest();
137+
$this->requireAjaxRequest();
138+
139+
$settings = array(
140+
'groupId' => craft()->request->getRequiredPost('group'),
141+
'name' => craft()->request->getRequiredPost('name'),
142+
'handle' => craft()->request->getRequiredPost('handle'),
143+
'instructions' => craft()->request->getRequiredPost('instructions'),
144+
//'translatable' => craft()->request->getPost('translatable'),
145+
'type' => craft()->request->getRequiredPost('type'),
146+
);
147+
148+
$returnData = craft()->superTable_table->createNewTable($settings);
149+
150+
$this->returnJson($returnData);
151+
}*/
152+
}
153+

0 commit comments

Comments
 (0)