summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/php/components/CalendarScaffold.php127
-rw-r--r--app/php/components/CalendarScaffold.tpl57
-rw-r--r--app/php/components/HeaderMenu.tpl4
-rw-r--r--app/php/pages/Admin.page6
4 files changed, 193 insertions, 1 deletions
diff --git a/app/php/components/CalendarScaffold.php b/app/php/components/CalendarScaffold.php
new file mode 100644
index 0000000..f265d53
--- /dev/null
+++ b/app/php/components/CalendarScaffold.php
@@ -0,0 +1,127 @@
+<?php
+
+Prado::using('System.Web.UI.ActiveControls.TActiveDataGrid');
+Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
+Prado::using('Application.facades.CalendarFacade');
+
+class CalendarScaffold extends TTemplateControl {
+
+ public function setFacade(Facade $facade) {
+ $this->setViewState('Facade', $facade);
+ }
+
+ public function getFacade() {
+ return $this->getViewState('Facade');
+ }
+
+ public function onPreRender($param) {
+ parent::onPreRender($param);
+ if (!$this->Page->IsPostBack && !$this->Page->IsCallBack) {
+ $this->_rebindData();
+ }
+ }
+
+ private function _rebindCalendars(array $calendars) {
+ $this->Calendars->DataSource = $calendars;
+ $this->Calendars->dataBind();
+ }
+
+ private function _rebindCategoryList(array $categories) {
+ foreach ($this->Calendars->Columns as $column) {
+ if ($column->ID === 'Category'
+ && $column instanceof TActiveDropDownListColumn) {
+ $column->ListDataSource = $categories;
+ }
+ }
+ }
+
+ private function _rebindData($refresh = FALSE) {
+ $this->_rebindCategoryList(
+ $this->_getCategories()
+ );
+ $this->_rebindCalendars(
+ $this->_getCalendars($refresh)
+ );
+ }
+
+ private function _getCalendars($refresh = FALSE) {
+ if ($refresh) {
+ $this->clearViewState('Calendars');
+ }
+ $calendars = $this->getViewState(
+ 'Calendars',
+ $this->getFacade()->getAll()
+ );
+ $this->setViewState('Calendars', $calendars);
+ return $calendars;
+ }
+
+ private function _getCategories() {
+ $categories = $this->getViewState(
+ 'Categories',
+ $this->getFacade()->getCategories()
+ );
+ $this->setViewState('Categories', $categories);
+ return $categories;
+ }
+
+ public function editRow($sender, $param) {
+ $this->Calendars->EditItemIndex = $param->Item->ItemIndex;
+ $this->_rebindData();
+ }
+
+ private function _compileSaveData(TDataGridItem $item) {
+ return [
+ 'CategoryID' => $item->Category->DropDownList->SelectedValue,
+ 'Visible' => $item->Visible->CheckBox->Checked,
+ 'CustomName' => $item->CustomName->TextBox->SafeText,
+ 'CustomUrl' => $item->CustomUrl->TextBox->SafeText,
+ 'CustomImage' => $item->CustomImage->Value->SafeText
+ ];
+ }
+
+ public function saveRow($sender, $param) {
+ $calendar = $this->getFacade()->get(
+ $sender->DataKeys[$param->Item->ItemIndex]
+ );
+ if ($calendar) {
+ foreach ($calendar as $c) {
+ $c->saveData($this->_compileSaveData($param->Item));
+ }
+ } else {
+ throw new TInvalidDataValueException('Calendar not found');
+ }
+ $this->Calendars->EditItemIndex = -1;
+ $this->_rebindData(TRUE);
+ }
+
+ public function cancelRowEdit($sender, $param) {
+ $this->Calendars->EditItemIndex = -1;
+ $this->_rebindData();
+ }
+
+ public function uploadRowFile($sender, $param) {
+ $fileType = $sender->getFileType();
+ if (preg_match('/^image\//', $fileType)) {
+ $calendar = $this->getFacade()->get($sender->CustomData);
+ if ($calendar) {
+ $targetFile = $calendar[0]->getCustomImagePath(
+ $sender->getLocalName(),
+ $fileType
+ );
+ if ($sender->saveAs($targetFile)) {
+ $sender->NamingContainer->CustomImage->Value->Text = basename(
+ $targetFile
+ );
+ }
+ } else {
+ throw new TInvalidDataValueException('Calendar not found');
+ }
+ } else {
+ throw new TInvalidDataTypeException('Invalid file type');
+ }
+ }
+
+}
+
+?>
diff --git a/app/php/components/CalendarScaffold.tpl b/app/php/components/CalendarScaffold.tpl
new file mode 100644
index 0000000..6688869
--- /dev/null
+++ b/app/php/components/CalendarScaffold.tpl
@@ -0,0 +1,57 @@
+<com:TActiveDataGrid ID="Calendars"
+ DataKeyField="UID"
+ AutoGenerateColumns="false"
+ OnEditCommand="editRow"
+ OnCancelCommand="cancelRowEdit"
+ OnUpdateCommand="saveRow">
+ <com:TActiveBoundColumn ID="Name"
+ ReadOnly="true"
+ HeaderText="Calendar"
+ DataField="Name" />
+ <com:TActiveHyperLinkColumn ID="Website"
+ HeaderText="WWW"
+ Text="[www]"
+ Target="_blank"
+ DataNavigateUrlField="Website" />
+ <com:TActiveHyperLinkColumn ID="Url"
+ HeaderText="ICS"
+ Text="[ics]"
+ Target="_blank"
+ DataNavigateUrlField="Url" />
+ <com:TActiveDropDownListColumn ID="Category"
+ HeaderText="Category"
+ DataTextField="Category.Name"
+ DataValueField="CategoryID"
+ ListValueField="ID"
+ ListTextField="Name" />
+ <com:TActiveCheckBoxColumn ID="Visible"
+ HeaderText="Default"
+ DataField="Visible" />
+ <com:TActiveBoundColumn ID="CustomName"
+ HeaderText="Name"
+ DataField="CustomName" />
+ <com:TActiveBoundColumn ID="CustomUrl"
+ HeaderText="URL"
+ DataField="CustomUrl" />
+ <com:TActiveTemplateColumn ID="CustomImage"
+ HeaderText="Image">
+ <prop:ItemTemplate>
+ <com:TImage>
+ <prop:ImageUrl><%# $this->Parent->Data->CustomImageUrl %></prop:ImageUrl>
+ </com:TImage>
+ </prop:ItemTemplate>
+ <prop:EditItemTemplate>
+ <com:TActiveTextBox ID="Value">
+ <prop:Text><%# $this->Parent->Data->CustomImage %></prop:Text>
+ </com:TActiveTextBox><br />
+ <com:SafeActiveFileUpload
+ OnFileUpload="SourceTemplateControl.uploadRowFile">
+ <prop:CustomData><%# $this->Parent->Data->UID %></prop:CustomData>
+ </com:SafeActiveFileUpload>
+ </prop:EditItemTemplate>
+ </com:TActiveTemplateColumn>
+ <com:TActiveEditCommandColumn
+ HeaderText="Edit"
+ UpdateText="Save"
+ CancelText="Cancel" />
+</com:TActiveDataGrid>
diff --git a/app/php/components/HeaderMenu.tpl b/app/php/components/HeaderMenu.tpl
index ff1d417..603a231 100644
--- a/app/php/components/HeaderMenu.tpl
+++ b/app/php/components/HeaderMenu.tpl
@@ -15,4 +15,8 @@
<prop:NavigateUrl><%= $this->Service->constructUrl('Signup') %></prop:NavigateUrl>
<prop:Visible><%= $this->User->getIsAdmin() %></prop:Visible>
</com:THyperLink>
+ <com:THyperLink Text="Admin calendars">
+ <prop:NavigateUrl><%= $this->Service->constructUrl('Admin') %></prop:NavigateUrl>
+ <prop:Visible><%= $this->User->getIsAdmin() %></prop:Visible>
+ </com:THyperLink>
</nav>
diff --git a/app/php/pages/Admin.page b/app/php/pages/Admin.page
index 8b13789..b130583 100644
--- a/app/php/pages/Admin.page
+++ b/app/php/pages/Admin.page
@@ -1 +1,5 @@
-
+<com:TContent ID="Content">
+ <com:CalendarScaffold>
+ <prop:Facade><%= CalendarFacade::getInstance() %></prop:Facade>
+ </com:CalendarScaffold>
+</com:TContent>