Skip to content

Commit b644096

Browse files
author
NiallSmyth
committed
Merge branch 'we-are-vertigo' into presenter-latest
# Conflicts: # composer.json
2 parents 2c60a15 + c776f8f commit b644096

File tree

13 files changed

+140
-20
lines changed

13 files changed

+140
-20
lines changed

src/Presenters/Application/Pager/Pager.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ protected function beforeRenderView()
123123
// that the data our collection uses is modified and because the collection is already
124124
// fetched, any presenters using the collection won't see the modification.
125125

126-
$this->setPageNumber($this->model->PageNumber);
126+
try {
127+
$this->setPageNumber($this->model->PageNumber);
128+
} catch (PagerOutOfBoundsException $ex) {
129+
$this->setPageNumber(1);
130+
}
127131

128132
$this->view->setNumberOfPages($this->NumberOfPages);
129133
$this->view->setNumberPerPage($this->model->PerPage);

src/Presenters/Application/Table/Columns/ModelColumn.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Rhubarb\Stem\Schema\Columns\BooleanColumn;
2828
use Rhubarb\Stem\Schema\Columns\Column;
2929
use Rhubarb\Stem\Schema\Columns\DateColumn;
30-
use Rhubarb\Stem\Schema\Columns\Float;
3130
use Rhubarb\Stem\Schema\Columns\FloatColumn;
3231
use Rhubarb\Stem\Schema\Columns\IntegerColumn;
3332
use Rhubarb\Stem\Schema\Columns\MoneyColumn;
@@ -121,4 +120,4 @@ public function getSortableColumnName()
121120
{
122121
return $this->sortColumnName;
123122
}
124-
}
123+
}

src/Presenters/Controls/Buttons/button.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ var button = function (presenterPath) {
55

66
window.rhubarb.viewBridgeClasses.JqueryHtmlViewBridge.apply(this, arguments);
77

8+
if (arguments.length == 0) {
9+
return;
10+
}
11+
812
this.useXmlRpc = ( this.element.attr("xmlrpc") == "yes" );
913

1014
if (this.element.attr("confirm")) {

src/Presenters/Controls/DateTime/date-picker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ datePicker.prototype.getSerializableValue = function() {
5151
var date = this.getDate();
5252

5353
if (date == null) {
54-
return null;
54+
return '';
5555
}
5656

5757
return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear();

src/Presenters/Controls/FileUpload/MultipleHtmlFileUpload.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,35 @@
2020

2121
require_once __DIR__ . '/SimpleHtmlFileUpload.php';
2222

23+
/**
24+
* @property int $MaxFileSize
25+
*/
2326
class MultipleHtmlFileUpload extends SimpleHtmlFileUpload
2427
{
28+
protected function initialiseModel()
29+
{
30+
parent::initialiseModel();
31+
32+
if ($this->MaxFileSize == null) {
33+
$returnBytes = function ($val) {
34+
$val = trim($val);
35+
$last = strtolower($val[strlen($val) - 1]);
36+
switch ($last) {
37+
case 'g':
38+
$val *= 1024;
39+
case 'm':
40+
$val *= 1024;
41+
case 'k':
42+
$val *= 1024;
43+
}
44+
45+
return $val;
46+
};
47+
48+
$this->MaxFileSize = min($returnBytes(ini_get('upload_max_filesize')), $returnBytes(ini_get('post_max_size')));
49+
}
50+
}
51+
2552
protected function getPublicModelPropertyList()
2653
{
2754
$properties = parent::getPublicModelPropertyList();
@@ -50,4 +77,4 @@ function () {
5077
}
5178
);
5279
}
53-
}
80+
}

src/Presenters/Controls/FileUpload/MultipleHtmlFileUploadViewBridge.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ var bridge = function (presenterPath) {
55
bridge.prototype = new window.rhubarb.viewBridgeClasses.SimpleHtmlFileUploadViewBridge();
66
bridge.prototype.constructor = bridge;
77

8-
bridge.prototype.onStateLoaded = function () {
9-
if (!this.model.MaxFileSize) {
10-
this.model.MaxFileSize = 5 * 1024 * 1024;
11-
}
12-
};
13-
148
bridge.prototype.supportsHtml5Uploads = function () {
159
var xhr = new XMLHttpRequest();
1610

@@ -49,7 +43,12 @@ bridge.prototype.filesSelected = function (files) {
4943
var self = this;
5044

5145
for (var i = 0, file; file = files[i]; i++) {
52-
var uploadFunction = function (file) {
46+
if (this.model.MaxFileSize && file.size > this.model.MaxFileSize) {
47+
this.onUploadFailed(file.name + ' is over the maximum file size of ' + this.formatBytes(this.model.MaxFileSize, 0));
48+
continue;
49+
}
50+
51+
var uploadFile = function (file) {
5352
self.sendFileAsServerEvent("FileUploadedXhr", file, function (e) {
5453
var progress =
5554
{
@@ -132,6 +131,22 @@ bridge.prototype.onUploadComplete = function (progressIndicator) {
132131
}, 3000);
133132
};
134133

134+
bridge.prototype.onUploadFailed = function (message) {
135+
var upiDom = document.createElement("div");
136+
upiDom.className = "upload-failed";
137+
138+
var upiLabel = document.createElement("label");
139+
upiLabel.innerHTML = message;
140+
141+
upiDom.appendChild(upiLabel);
142+
143+
this.attachUploadProgressIndicator(upiDom);
144+
145+
setTimeout(function () {
146+
upiDom.parentNode.removeChild(upiDom);
147+
}, 3000);
148+
};
149+
135150
bridge.prototype.addClass = function (nodes, className) {
136151
if (!nodes.length) {
137152
nodes = [nodes];
@@ -157,4 +172,14 @@ bridge.prototype.removeClass = function (nodes, className) {
157172
}
158173
};
159174

160-
window.rhubarb.viewBridgeClasses.MultipleHtmlFileUploadViewBridge = bridge;
175+
bridge.prototype.formatBytes = function (bytes, decimals) {
176+
if (bytes == 0) {
177+
return '0B';
178+
}
179+
var k = 1000;
180+
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
181+
var i = Math.floor(Math.log(bytes) / Math.log(k));
182+
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + sizes[i];
183+
};
184+
185+
window.rhubarb.viewBridgeClasses.MultipleHtmlFileUploadViewBridge = bridge;

src/Presenters/Controls/FileUpload/SimpleHtmlFileUploadViewBridge.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@ bridge.spawn = function (spawnSettings, viewIndex, parentPresenterPath) {
1414
return element;
1515
};
1616

17-
window.rhubarb.viewBridgeClasses.SimpleHtmlFileUploadViewBridge = bridge;
17+
bridge.prototype.reset = function ()
18+
{
19+
var form = document.createElement("FORM");
20+
var currentParent = this.viewNode.parentNode;
21+
currentParent.insertBefore(form, this.viewNode);
22+
form.appendChild(this.viewNode);
23+
form.reset();
24+
currentParent.insertBefore(this.viewNode, form);
25+
currentParent.removeChild(form);
26+
};
27+
28+
window.rhubarb.viewBridgeClasses.SimpleHtmlFileUploadViewBridge = bridge;

src/Presenters/Controls/Selection/RadioButtons/RadioButtonsView.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,16 @@ public function getItemOptionHtml($value, $label, $item, $classSuffix = "radio")
4141
{
4242
return parent::getItemOptionHtml($value, $label, $item, $classSuffix);
4343
}
44-
}
44+
45+
protected function getClientSideViewBridgeName()
46+
{
47+
return 'RadioButtonsViewBridge';
48+
}
49+
50+
public function getDeploymentPackage()
51+
{
52+
$package = parent::getDeploymentPackage();
53+
$package->resourcesToDeploy[] = __DIR__ . '/RadioButtonsViewBridge.js';
54+
return $package;
55+
}
56+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var radioButtonsViewBridge = function (presenterPath) {
2+
window.rhubarb.viewBridgeClasses.SelectionControlViewBridge.apply(this, arguments);
3+
4+
this.supportsMultipleSelection = false;
5+
};
6+
7+
radioButtonsViewBridge.prototype = new window.rhubarb.viewBridgeClasses.SelectionControlViewBridge();
8+
radioButtonsViewBridge.prototype.constructor = radioButtonsViewBridge;
9+
10+
radioButtonsViewBridge.prototype.setValue = function (value) {
11+
this.element.find('input[type=radio][value=' + value + ']').prop('checked', true);
12+
13+
this.model.SelectedItems = [{"value": value}];
14+
15+
this.valueChanged();
16+
};
17+
18+
radioButtonsViewBridge.prototype.valueChanged = function () {
19+
var checked = this.element.find("input:checked");
20+
21+
this.model.SelectedItems = [{"value": checked.length ? checked.val() : null}];
22+
23+
// Calling our parent will ensure the new value gets raised as an event
24+
window.rhubarb.viewBridgeClasses.SelectionControlViewBridge.prototype.valueChanged.apply(this, arguments);
25+
};
26+
27+
window.rhubarb.viewBridgeClasses.RadioButtonsViewBridge = radioButtonsViewBridge;

src/Presenters/Controls/Text/TextBox/TextBoxView.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public function getSpawnSettings()
107107
$settings["size"] = $this->size;
108108
$settings["maxLength"] = $this->maxLength;
109109
$settings["allowBrowserAutoComplete"] = $this->allowBrowserAutoComplete;
110+
$settings["placeholderText"] = $this->placeholderText;
110111

111112
return $settings;
112113
}

src/Presenters/Controls/Text/TextBox/TextBoxViewBridge.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ bridge.spawn = function (spawnData, index, parentPresenterPath) {
1212
if (spawnData.maxLength) {
1313
textBox.setAttribute("maxlength", spawnData.maxLength);
1414
}
15+
if (spawnData.placeholderText) {
16+
textBox.setAttribute("placeholder", spawnData.placeholderText);
17+
}
1518

1619
window.rhubarb.viewBridgeClasses.HtmlViewBridge.applyStandardAttributesToSpawnedElement(textBox, spawnData, index, parentPresenterPath);
1720

src/Presenters/Presenter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,10 +1153,6 @@ public final function generateResponse($request = null)
11531153
ob_start();
11541154

11551155
if ($this->isExecutionTarget) {
1156-
if ($isAjax) {
1157-
print "<?xml version=\"1.0\"?><mvp>\r\n";
1158-
}
1159-
11601156
// Process events and if based on those events our view setup might change we
11611157
// will reinitialise them and run the events again. This is because a new view
11621158
// configuration may involve different presenters that will need a chance to run their
@@ -1193,6 +1189,10 @@ public final function generateResponse($request = null)
11931189
if ($isAjax) {
11941190
$response = new HtmlResponse($this);
11951191

1192+
if ($isAjax) {
1193+
$html = "<?xml version=\"1.0\"?><mvp>\r\n" . $html;
1194+
}
1195+
11961196
if ($this->isExecutionTarget) {
11971197
foreach ($modelChanges as $path => $modelChange) {
11981198
$html .= "<model id=\"" . $path . "\"><![CDATA[" . json_encode($modelChange) . "]]></model>";

src/Views/HtmlViewBridge.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,14 @@ HtmlViewBridge.prototype.parseEventResponse = function (eventName, responseCode,
10081008
var response = ( eventResponse.textContent ) ? eventResponse.textContent : eventResponse.text;
10091009

10101010
if (eventResponse.getAttribute("type") == "json") {
1011-
response = JSON.parse(response);
1011+
try {
1012+
response = JSON.parse(response);
1013+
} catch (exception) {
1014+
if (failureCallback) {
1015+
failureCallback(response, responseCode, exception);
1016+
callBackCalled = true;
1017+
}
1018+
}
10121019
}
10131020
else {
10141021
response = response.trim();

0 commit comments

Comments
 (0)