more work on CRM-12965, added basic form and page structure
authorKurund Jalmi <kurund@civicrm.org>
Fri, 28 Jun 2013 19:48:41 +0000 (01:18 +0530)
committerKurund Jalmi <kurund@civicrm.org>
Fri, 28 Jun 2013 19:48:41 +0000 (01:18 +0530)
CRM/Badge/Form/Layout.php [new file with mode: 0644]
CRM/Badge/Page/Layout.php [new file with mode: 0644]
CRM/Core/xml/Menu/Admin.xml
templates/CRM/Badge/Form/Layout.tpl [new file with mode: 0644]
templates/CRM/Badge/Page/Layout.tpl [new file with mode: 0644]

diff --git a/CRM/Badge/Form/Layout.php b/CRM/Badge/Form/Layout.php
new file mode 100644 (file)
index 0000000..485610e
--- /dev/null
@@ -0,0 +1,128 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * This class generates form components for name badge layout
+ *
+ */
+class CRM_Badge_Form_Layout extends CRM_Admin_Form {
+
+  /**
+   * Function to build the form
+   *
+   * @return None
+   * @access public
+   */
+  public function buildQuickForm() {
+
+    parent::buildQuickForm();
+
+    if ($this->_action & CRM_Core_Action::DELETE) {
+      return;
+    }
+
+    $this->applyFilter('__ALL__', 'trim');
+    $this->add('text',
+      'name',
+      ts('Name'),
+      CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'name'),
+      TRUE
+    );
+    $this->addRule('name',
+      ts('Name already exists in Database.'),
+      'objectExists',
+      array('CRM_Core_DAO_PrintLabel', $this->_id)
+    );
+    $this->addRule('name',
+      ts('Name can only consist of alpha-numeric characters'),
+      'variable'
+    );
+
+    $this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'display_name'));
+    $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'description'));
+    $this->add('checkbox', 'is_active', ts('Enabled?'));
+    $this->add('checkbox', 'is_default', ts('Default?'));
+
+    if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PrintLabel', $this->_id, 'is_reserved')) {
+      $this->freeze(array('name', 'description', 'is_active'));
+    }
+  }
+
+  /**
+   * Function to process the form
+   *
+   * @access public
+   *
+   * @return None
+   */
+  public function postProcess() {
+    /*
+        if ($this->_action & CRM_Core_Action::DELETE) {
+          CRM_Core_BAO_LocationType::del($this->_id);
+          CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success');
+          return;
+        }
+
+        // store the submitted values in an array
+        $params = $this->exportValues();
+        $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
+        $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
+
+        // action is taken depending upon the mode
+        $locationType = new CRM_Core_DAO_PrintLabel();
+        $locationType->name = $params['name'];
+        $locationType->display_name = $params['display_name'];
+        $locationType->vcard_name = $params['vcard_name'];
+        $locationType->description = $params['description'];
+        $locationType->is_active = $params['is_active'];
+        $locationType->is_default = $params['is_default'];
+
+        if ($params['is_default']) {
+          $query = "UPDATE civicrm_location_type SET is_default = 0";
+          CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
+        }
+
+        if ($this->_action & CRM_Core_Action::UPDATE) {
+          $locationType->id = $this->_id;
+        }
+
+        $locationType->save();
+
+    CRM_Core_Session::setStatus(ts("The location type '%1' has been saved.",
+        array(1 => $locationType->name)
+      ), ts('Saved'), 'success');
+    */
+  }
+}
diff --git a/CRM/Badge/Page/Layout.php b/CRM/Badge/Page/Layout.php
new file mode 100644 (file)
index 0000000..062d89d
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * Page for list page badges
+ */
+class CRM_Badge_Page_Layout extends CRM_Core_Page_Basic {
+
+  /**
+   * The action links that we need to display for the browse screen
+   *
+   * @var array
+   * @static
+   */
+  static $_links = NULL;
+
+  /**
+   * Get BAO Name
+   *
+   * @return string Classname of BAO.
+   */
+  function getBAOName() {
+    return 'CRM_Core_DAO_PrintLabel';
+  }
+
+  /**
+   * Get action Links
+   *
+   * @return array (reference) of action links
+   */
+  function &links() {
+    if (!(self::$_links)) {
+      self::$_links = array(
+        CRM_Core_Action::UPDATE => array(
+          'name' => ts('Edit'),
+          'url' => 'civicrm/admin/badgelayout',
+          'qs' => 'action=update&id=%%id%%&reset=1',
+          'title' => ts('Edit Badge Layout'),
+        ),
+        CRM_Core_Action::DISABLE => array(
+          'name' => ts('Disable'),
+          'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_DAO_PrintLabel' . '\',\'' . 'enable-disable' . '\' );"',
+          'ref' => 'disable-action',
+          'title' => ts('Disable Badge Layout'),
+        ),
+        CRM_Core_Action::ENABLE => array(
+          'name' => ts('Enable'),
+          'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_DAO_PrintLabel' . '\',\'' . 'disable-enable' . '\' );"',
+          'ref' => 'enable-action',
+          'title' => ts('Enable Badge Layout'),
+        ),
+        CRM_Core_Action::DELETE => array(
+          'name' => ts('Delete'),
+          'url' => 'civicrm/admin/badgelayout',
+          'qs' => 'action=delete&id=%%id%%',
+          'title' => ts('Delete Badge Layout'),
+        ),
+      );
+    }
+    return self::$_links;
+  }
+
+  /**
+   * Get name of edit form
+   *
+   * @return string Classname of edit form.
+   */
+  function editForm() {
+    return 'CRM_Badge_Form_Layout';
+  }
+
+  /**
+   * Get edit form name
+   *
+   * @return string name of this page.
+   */
+  function editName() {
+    return 'Badge Layout';
+  }
+
+  /**
+   * Get user context.
+   *
+   * @return string user context.
+   */
+  function userContext($mode = NULL) {
+    return 'civicrm/admin/badgelayout';
+  }
+}
+
index c622cb4494221b085413bf3f184ca34abc46b997..dddc1db5d016733bb26a7dd90c6e716ef4a10e58 100644 (file)
      <page_callback>CRM_SMS_Page_Callback</page_callback>
      <access_callback>1</access_callback>
   </item>
+  <item>
+    <path>civicrm/admin/badgelayout</path>
+    <title>Badge Layout</title>
+    <page_callback>CRM_Badge_Page_Layout</page_callback>
+    <access_arguments>administer CiviCRM,access CiviEvent</access_arguments>
+  </item>
+  <item>
+    <path>civicrm/admin/badgelayout/add</path>
+    <page_callback>CRM_Badge_Form_Layout</page_callback>
+    <access_arguments>administer CiviCRM,access CiviEvent</access_arguments>
+  </item>
 </menu>
diff --git a/templates/CRM/Badge/Form/Layout.tpl b/templates/CRM/Badge/Form/Layout.tpl
new file mode 100644 (file)
index 0000000..c3734ae
--- /dev/null
@@ -0,0 +1,66 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+{* this template is used for adding/editing badge layouts *}
+<h3>{if $action eq 1}{ts}New Badge Layout{/ts}{elseif $action eq 2}{ts}Edit Badge Layout{/ts}{else}{ts}Delete Badge Layout{/ts}{/if}</h3>
+<div class="crm-block crm-form-block crm-badge-layout-form-block">
+  <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
+  {if $action eq 8}
+    <div class="messages status no-popup">
+      <div class="icon inform-icon"></div>
+      {ts}WARNING: Deleting this option will result in the loss of all location type records which use the option.{/ts} {ts}This may mean the loss of a substantial amount of data, and the action cannot be undone.{/ts} {ts}Do you want to continue?{/ts}
+    </div>
+  {else}
+    <table class="form-layout-compressed">
+      <!--tr class="crm-badge-layout-form-block-label">
+        <td class="label">{$form.name.label}</td>
+        <td>{$form.name.html}<br/>
+          <span class="description">{ts}WARNING: Do NOT use spaces in the Location Name.{/ts}</span>
+        </td>
+      </tr-->
+      <tr class="crm-badge-layout-form-block-title">
+        <td class="label">{$form.title.label}</td>
+        <td>{$form.title.html}</td>
+      </tr>
+      <tr class="crm-badge-layout-form-block-description">
+        <td class="label">{$form.description.label}</td>
+        <td>{$form.description.html}</td>
+      </tr>
+      <tr class="crm-badge-layout-form-block-is_active">
+        <td class="label">{$form.is_active.label}</td>
+        <td>{$form.is_active.html}</td>
+      </tr>
+      <tr class="crm-badge-layout-form-block-is_default">
+        <td class="label">{$form.is_default.label}</td>
+        <td>{$form.is_default.html}</td>
+      </tr>
+      <tr class="crm-badge-layout-form-block-is_reserved">
+        <td class="label">{$form.is_reserved.label}</td>
+        <td>{$form.is_reserved.html}</td>
+      </tr>
+    </table>
+  {/if}
+  <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
+</div>
diff --git a/templates/CRM/Badge/Page/Layout.tpl b/templates/CRM/Badge/Page/Layout.tpl
new file mode 100644 (file)
index 0000000..1c3d2e9
--- /dev/null
@@ -0,0 +1,83 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+<div id="help">
+  {ts}Badge Layout.{/ts}
+</div>
+
+{if $action eq 1 or $action eq 2 or $action eq 8}
+  {include file="CRM/Badge/Form/Layout.tpl"}
+{else}
+
+  {if $rows}
+    <div id="badge-layout">
+      {strip}
+      {* handle enable/disable actions*}
+        {include file="CRM/common/enableDisable.tpl"}
+        {include file="CRM/common/jsortable.tpl"}
+        <table id="options" class="display">
+          <thead>
+          <tr>
+            <th id="sortable">{ts}Title{/ts}</th>
+            <th id="nosort">{ts}Description{/ts}</th>
+            <th>{ts}Enabled?{/ts}</th>
+            <th>{ts}Default?{/ts}</th>
+            <th></th>
+          </tr>
+          </thead>
+          {foreach from=$rows item=row}
+            <tr id="row_{$row.id}"
+                class="{cycle values="odd-row,even-row"} {$row.class} crm-badge-layout {if NOT $row.is_active} disabled{/if}">
+              <td class="crm-badge-layout-title">{$row.title}</td>
+              <td class="crm-badge-layout-description">{$row.description}</td>
+              <td id="row_{$row.id}_status" class="crm-badge-layout-is_active">
+                {if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}
+              </td>
+              <td class="crm-badge-layout-is_default">
+                {if $row.is_default eq 1}
+                <img src="{$config->resourceBase}i/check.gif" alt="{ts}Default{/ts}"/>
+                {/if}&nbsp;
+              </td>
+              <td>{$row.action|replace:'xx':$row.id}</td>
+            </tr>
+          {/foreach}
+        </table>
+      {/strip}
+
+      {if $action ne 1 and $action ne 2}
+        <div class="action-link">
+          <a href="{crmURL q="action=add&reset=1"}" id="newbadge-layout"
+             class="button"><span>&raquo; {ts}New Badge Layout{/ts}</span></a>
+        </div>
+      {/if}
+    </div>
+  {else}
+    <div class="messages status no-popup">
+      <img src="{$config->resourceBase}i/Inform.gif" alt="{ts}status{/ts}"/>
+      {capture assign=crmURL}{crmURL p='civicrm/admin/badgelayout' q="action=add&reset=1"}{/capture}
+      {ts 1=$crmURL}There are no Badge Layout entered for this Contact. You can<a href='%1'>add one</a>.{/ts}
+    </div>
+  {/if}
+{/if}