Skip to content

Instantly share code, notes, and snippets.

@sminnee
Created November 5, 2009 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sminnee/226609 to your computer and use it in GitHub Desktop.
Save sminnee/226609 to your computer and use it in GitHub Desktop.
diff --git a/app/code/control/Dashboard.php b/app/code/control/Dashboard.php
index 072fd62..e72f9a7 100644
--- a/app/code/control/Dashboard.php
+++ b/app/code/control/Dashboard.php
@@ -359,6 +359,50 @@ class Dashboard extends Controller {
}
/**
+ * Settings form for configuring guardian
+ */
+ function SettingsForm() {
+ $form = new Form($this, "SettingsForm", new FieldSet(
+ new TextField("PageExecTimeCritical", "Critical threshold (ms)"),
+ new TextField("PageExecTimeWarning", "Warning threshold (ms)"),
+ new CheckboxField("CriticalAlertNotifications", "For critical events"),
+ new CheckboxField("RegularAlertNotifications", "For warnings")
+ ), new FieldSet(
+ new FormAction('doSaveSettings', 'Save changes')
+ ));
+
+ // Load the applicable fields from the site object
+ $form->loadDataFrom($this->CurrentSite(), false,
+ array('PageExecTimeCritical', 'PageExecTimeWarning'));
+
+ // Load the applicable fields from the member object
+ $form->loadDataFrom(Member::currentUser(), false,
+ array('CriticalAlertNotifications', 'RegularAlertNotifications'));
+
+ return $form;
+ }
+
+ function doSaveSettings($data, $form) {
+ $member = Member::currentUser();
+ $site = $this->CurrentSite();
+
+ $form->saveInto($member, array('CriticalAlertNotifications', 'RegularAlertNotifications'));
+ $form->saveInto($site, array('PageExecTimeCritical', 'PageExecTimeWarning'));
+
+ $member->write();
+ $site->write();
+
+ if($this->isAjax()) {
+ $response = new SS_HTTPResponse("200", "Changes saved");
+ $response->addHeader("Content-type", "text/plain");
+ return $respponse;
+
+ } else {
+ Director::redirectBack();
+ }
+ }
+
+ /**
* Used for some crude template switching in terms of displaying menus conditionally.
*
* @return String
diff --git a/themes/guardian/templates/Dashboard.ss b/themes/guardian/templates/Dashboard.ss
index 8ee2ae5..63deda4 100644
--- a/themes/guardian/templates/Dashboard.ss
+++ b/themes/guardian/templates/Dashboard.ss
@@ -34,34 +34,39 @@
<!-- SETTINGS FORM -->
<div class="panel" id="settings">
<h2>Settings</h2>
- <form action="">
+ <% control SettingsForm %>
+ <form $FormAttributes>
+ <% control FieldMap %>
<fieldset>
<h3>Page generation time</h3>
<div class="field text">
- <label for="page-gen-threshold-critical">Critical threshold (<abbr title="milliseconds">ms</abbr>)</label>
- <input class="text" type="text" id="page-gen-threshold-critical" name="page-gen-threshold-critical" value="400" />
+ <label for="$PageExecTimeCritical.ID">Critical threshold (<abbr title="milliseconds">ms</abbr>)</label>
+ $PageExecTimeCritical
</div>
<div class="field text">
- <label for="page-gen-threshold-warning">Warning threshold (<abbr title="milliseconds">ms</abbr>)</label>
- <input class="text" type="text" id="page-gen-threshold-warning" name="page-gen-threshold-warning" value="100" />
+ <label for="$PageExecTimeWarning.ID">Warning threshold (<abbr title="milliseconds">ms</abbr>)</label>
+ $PageExecTimeWarning
</div>
</fieldset>
<fieldset>
- <h3>Send me email alerts <span>($CurrentMember.Email)</span></h3>
+ <h3>Send me email alerts <span>($Top.CurrentMember.Email)</span></h3>
<div class="field checkbox">
- <input class="checkbox" type="checkbox" id="send-critical" name="send-critical" checked="checked" />
- <label for="send-critical">For critical events</label>
+ $CriticalAlertNotifications
+ <label for="$CriticalAlertNotifications.ID">For critical events</label>
<br/>
- <input class="checkbox" type="checkbox" id="send-warnings" name="send-warnings" checked="checked" />
- <label for="send-warnings">For warnings</label>
+ $RegularAlertNotifications
+ <label for="$RegularAlertNotifications.ID">For warnings</label>
</div>
</fieldset>
+ <% end_control %>
+
<fieldset class="actions">
<div class="field actions">
- <input class="action" type="submit" value="Save changes" />
+ <% control Actions %> $Field <% end_control %>
</div>
</fieldset>
</form>
+ <% end_control %>
</div>
<!-- FEEDBACK FORM -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment