9826: Default course type
authorsstamer <s.stamer@metaways.de>
Fri, 11 Apr 2014 11:50:28 +0000 (13:50 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 11 Apr 2014 12:02:07 +0000 (14:02 +0200)
https://forge.tine20.org/mantisbt/view.php?id=9826
- add default department option

Change-Id: I0bf7463009249107c08134f47544798155cb0b47
Reviewed-on: http://gerrit.tine20.com/customers/515
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Courses/JsonTest.php
tine20/Courses/Config.php
tine20/Courses/Frontend/Json.php
tine20/Courses/js/CourseEditDialog.js

index 894410e..74ed6f6 100644 (file)
@@ -48,10 +48,21 @@ class Courses_JsonTest extends TestCase
     protected $_schemaConfig;
     
     /**
+     * The default department
+     * @var string
+     */
+    protected $_defaultDepartmentConfig;
+    
+    /**
      * @var Boolean
      */
     protected $_schemaConfigChanged = FALSE;
     
+     /**
+     * @var Boolean
+     */
+    protected $_defaultDepartmentConfigChanged = FALSE;
+    
     /**
      * Sets up the fixture.
      * This method is called before a test is executed.
@@ -86,6 +97,7 @@ class Courses_JsonTest extends TestCase
         )));
         
         $this->_schemaConfig = Courses_Config::getInstance()->get(Courses_Config::STUDENTS_USERNAME_SCHEMA);
+        $this->_defaultDepartmentConfig = Courses_Config::getInstance()->get(Courses_Config::DEFAULT_DEPARTMENT);
     }
 
     /**
@@ -101,6 +113,9 @@ class Courses_JsonTest extends TestCase
             Courses_Config::getInstance()->set(Courses_Config::STUDENTS_USERNAME_SCHEMA, $this->_schemaConfig);
         }
         
+        if ($this->_defaultDepartmentConfigChanged) {
+            Courses_Config::getInstance()->set(Courses_Config::DEFAULT_DEPARTMENT, $this->_defaultDepartmentConfig);
+        }
         parent::tearDown();
     }
     
@@ -463,6 +478,17 @@ class Courses_JsonTest extends TestCase
         $this->assertEquals('j.hot', $newUser->accountLoginName);
     }
     
+    /**
+     * Test if the default department is returned
+     */
+    public function testDefaultDepartment()
+    {
+        $this->_defaultDepartmentConfigChanged = true;
+        Courses_Config::getInstance()->set(Courses_Config::DEFAULT_DEPARTMENT, $this->_department->name);
+        $result = $this->_json->getRegistryData();
+        $this->assertEquals($this->_department->id, $result['defaultType']['value']);
+    }
+    
     /************ protected helper funcs *************/
     
     /**
index d5d9a2f..b986e42 100644 (file)
@@ -74,6 +74,13 @@ class Courses_Config extends Tinebase_Config_Abstract
     const STUDENT_LOGINNAME_PREFIX = 'student_loginname_prefix';
     
     /**
+    * default department
+    *
+    * @var string
+    */
+    const DEFAULT_DEPARTMENT = 'default_department';
+    
+    /**
      * (non-PHPdoc)
      * @see tine20/Tinebase/Config/Definition::$_properties
      */
@@ -146,6 +153,16 @@ class Courses_Config extends Tinebase_Config_Abstract
             'setByAdminModule'      => FALSE,
             'setBySetupModule'      => TRUE,
         ),
+        self::DEFAULT_DEPARTMENT => array(
+                                   //_('Default department')
+            'label'                 => 'Default department',
+                                   //_('The default department for new Courses')
+            'description'           => 'The default department for new Courses',
+            'type'                  => 'string',
+            'class'                 => 'Tinebase_Config_Struct',
+            'default'               => '',
+            'clientRegistryInclude' => TRUE,
+        ),
         
     );
     
index 420ea6e..3a17513 100644 (file)
@@ -142,10 +142,19 @@ class Courses_Frontend_Json extends Tinebase_Frontend_Json_Abstract
      */
     public function getRegistryData()
     {
+        $config = Courses_Config::getInstance();
         $courseTypes = Tinebase_Department::getInstance()->search(new Tinebase_Model_DepartmentFilter());
         
-        $defaultType = count($courseTypes) > 0 ? $courseTypes[0]->getId() : '';
-        
+        if (isset($config->default_department)) {
+            for ($i = 0; $i <= count($courseTypes); $i ++) {
+                if ($courseTypes[$i]->name == $config->default_department) {
+                    $defaultType = $courseTypes[$i]->getId();
+                    break;
+                }
+            }
+        } else {
+            $defaultType = count($courseTypes) > 0 ? $courseTypes[0]->getId() : '';
+        }
         $result = array(
             'defaultType' => array(
                 'value' => $defaultType,
index 59489eb..0353a56 100644 (file)
@@ -216,8 +216,7 @@ Tine.Courses.CourseEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
                            fields: Tine.Courses.Model.CourseType,
                            proxy:  Tine.Courses.courseTypeBackend,
                            reader: Tine.Courses.courseTypeBackend.getReader(),
-                           remoteSort: true,
-                           sortInfo: {field: 'name', dir: 'ASC'}
+                           sortInfo: {field: 'name', direction: 'ASC'}
                         })
                     }, {
                         name: 'description',