Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0 compat continuation #37

Merged
merged 13 commits into from
May 18, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Upgrade to SilverStripe 3.0 compatible version

## EditableCountryDropdownField

EditableCountryDropdownField is gone since the CountryDropdownField and GeoIP code has been removed from the SS framework.

22 changes: 9 additions & 13 deletions code/formfields/SubmittedFormReportField.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,30 @@ public function Field($properties = array()) {
*
* @return PaginatedList
*/
public function getSubmissions($start = 0) {
public function getSubmissions($page = 1) {
$record = $this->form->getRecord();
$submissions = $record->getComponents('Submissions', null, "\"Created\" DESC");

$query = DB::query(sprintf("
SELECT COUNT(*) AS \"CountRows\"
FROM \"SubmittedForm\"
WHERE \"ParentID\" = '%d'", $record->ID
));

foreach($query as $r) $totalCount = $r['CountRows'];
$query = DB::query(sprintf("SELECT COUNT(*) AS \"CountRows\" FROM \"SubmittedForm\" WHERE \"ParentID\" = '%d'", $record->ID));
$totalCount = 0;
foreach($query as $r) {
$totalCount = $r['CountRows'];
}

$list = new PaginatedList($submissions);
$list->setPageStart($start);
$list->setCurrentPage($page);
$list->setPageLength(10);
$list->setTotalItems($totalCount);

return $list;
}

/**
* @return string
*/
public function getMoreSubmissions() {
$start = ($start = $this->request->getVar('start')) ? (int) $start : 0;

$page = ($page = $this->request->getVar('page')) ? (int)$page : 1;
return $this->customise(new ArrayData(array(
'Submissions' => $this->getSubmissions($start)
'Submissions' => $this->getSubmissions($page)
)))->renderWith(array('SubmittedFormReportField'));
}

Expand Down
14 changes: 10 additions & 4 deletions code/model/UserDefinedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ public function process($data, $form) {
}

if(Session::get("FormInfo.{$form->FormName()}.errors")){
Director::redirectBack();
Controller::curr()->redirectBack();
return;
}

Expand Down Expand Up @@ -701,8 +701,14 @@ public function process($data, $form) {
$upload = new Upload();
$file = new File();
$file->ShowInSearch = 0;

$upload->loadIntoFile($_FILES[$field->Name], $file);
try {
$upload->loadIntoFile($_FILES[$field->Name], $file);
} catch( ValidationException $e ) {
$validationResult = $e->getResult();
$form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
Controller::curr()->redirectBack();
return;
}

// write file to form field
$submittedField->UploadedFileID = $file->ID;
Expand Down Expand Up @@ -734,7 +740,7 @@ public function process($data, $form) {
if($attachments){
foreach($attachments as $file){
if($file->ID != 0) {
$email->attachFile($file->Filename,$file->Filename, HTTP::getMimeType($file->Filename));
$email->attachFile($file->Filename, $file->Filename, HTTP::get_mime_type($file->Filename));
}
}
}
Expand Down
28 changes: 0 additions & 28 deletions code/model/formfields/EditableCountryDropdownField.php

This file was deleted.

29 changes: 5 additions & 24 deletions code/model/formfields/EditableDateField.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,14 @@ public function populateFromPostData($data) {
}

/**
* Return the form field.
* Return the form field
*
* @todo Make a jQuery safe form field. The current CalendarDropDown
* breaks on the front end.
*/
public function getFormField() {
// scripts for jquery date picker
Requirements::javascript(THIRDPARTY_DIR .'/jquery-ui/jquery.ui.core.js');
Requirements::javascript(THIRDPARTY_DIR .'/jquery-ui/jquery.ui.datepicker.js');

$dateFormat = DateField_View_JQuery::convert_iso_to_jquery_format(i18n::get_date_format());

Requirements::customScript(<<<JS
(function(jQuery) {
$(document).ready(function() {
$('input[name^=EditableDateField]').attr('autocomplete', 'off').datepicker({ dateFormat: '$dateFormat' });
});
})(jQuery);
JS
, 'UserFormsDate');

// css for jquery date picker
Requirements::css(THIRDPARTY_DIR .'/jquery-ui-themes/smoothness/jquery-ui-1.8rc3.custom.css');

$default = ($this->getSetting('DefaultToToday')) ? date('d/m/Y') : $this->Default;

return new DateField( $this->Name, $this->Title, $default);
$defaultValue = ($this->getSetting('DefaultToToday')) ? date('Y-m-d') : $this->Default;
$field = new DateField( $this->Name, $this->Title, $defaultValue);
$field->setConfig('showcalendar', true);
return $field;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions code/model/formfields/EditableMemberListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function getFieldConfiguration() {
$groupID = ($this->getSetting('GroupID')) ? $this->getSetting('GroupID') : 0;
$groups = DataObject::get("Group");

if($groups) $groups = $groups->toDropdownMap('ID', 'Title');
if($groups) $groups = $groups->map('ID', 'Title');

$fields = new FieldList(
new DropdownField("Fields[$this->ID][CustomSettings][GroupID]", _t('EditableFormField.GROUP', 'Group'), $groups, $groupID)
Expand All @@ -26,7 +26,7 @@ public function getFieldConfiguration() {

public function getFormField() {
if ($this->getSetting('GroupID')) {
$members = Member::mapInGroups($this->getSetting('GroupID'));
$members = Member::map_in_groups($this->getSetting('GroupID'));

return new DropdownField($this->Name, $this->Title, $members);
}
Expand Down
16 changes: 14 additions & 2 deletions code/model/submissions/SubmittedFileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ class SubmittedFileField extends SubmittedFormField {
* @return string
*/
public function getFormattedValue() {
$name = $this->getName();
$link = $this->getLink();
$title = _t('SubmittedFileField.DOWNLOADFILE', 'Download File');

if($link) {
return sprintf('<a href="%s">%s</a>', $link, $title);
return sprintf('%s - <a href="%s" target="_blank">%s</a>', $name, $link, $title);
}

return false;
Expand All @@ -49,5 +50,16 @@ public function getLink() {
return $this->UploadedFile()->URL;
}
}
}
}

/**
* Return the name of the file, if present
*
* @return string
*/
public function getName() {
if($this->UploadedFile()) {
return $this->UploadedFile()->Name;
}
}
}
6 changes: 3 additions & 3 deletions code/model/submissions/SubmittedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

class SubmittedForm extends DataObject {

static $has_one = array(
public static $has_one = array(
"SubmittedBy" => "Member",
"Parent" => "UserDefinedForm",
);

static $has_many = array(
public static $has_many = array(
"Values" => "SubmittedFormField"
);

/**
* Before we delete this form make sure we delete all the
* field values so that we don't leave old data round
Expand Down
5 changes: 2 additions & 3 deletions css/FieldEditor.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
border: 1px solid #ddd;
background: #f4f4f4;
overflow: hidden;
padding: 4px 0;
width: 100%;
}
.MenuHolder h2 {
Expand All @@ -21,13 +20,13 @@
.MenuHolder select {
float: left;
width: 240px;
margin: 7px 0 0 8px;
margin: 18px 0 0 8px;
font-size: 11px;
}

.MenuHolder .action {
float: left;
margin: 7px 0 0 4px;
margin: 14px 0 0 4px;
font-size: 11px;
}

Expand Down
Loading