. Table column adjustments
authorJoey Schulze <joey@infodrom.org>
Thu, 4 Mar 2010 21:22:54 +0000 (22:22 +0100)
committerJoey Schulze <joey@infodrom.org>
Thu, 4 Mar 2010 21:22:54 +0000 (22:22 +0100)
 . Add edit possibility for secondary table
 . Install callback to get information based on selection

masks/materialverbrauch.php

index 61d9cf3..c80d67f 100644 (file)
@@ -1,42 +1,88 @@
 <?php
 
+$jscode[] = <<<EOC
+
+Rico.moduleDependencies['checkboxDB'] = ['+LiveGrid', '../ricoTableColumnDB.js'];
+Rico.loadModule('checkboxDB');
+
+function einheit_callback(data)
+{
+  var einheit = document.getElementById('edit_einheit');
+
+  if (!einheit) return false;
+
+  if (data.info[0].einheit.length)
+    einheit.innerHTML = data.info[0].einheit;
+}
+
+function select_material(obj)
+{
+  get_info('einheit', {id: obj.options[obj.selectedIndex].value}, einheit_callback);
+}
+
+EOC;
+
 $mask = array(
-             'table' => 'materialverbrauch',
-             'join' => array('materialien ON materialverbrauch.material = materialien.id'),
+             'table' => 'einsatz',
+             'title' => 'Materialverbrauch zu Arbeitsberichten',
+             'join' => array('kostenstellen ON einsatz.kostenstelle = kostenstellen.id'),
              'list' => array(
                              'id' => array(
                                            'name' => 'ID',
-                                           'sql' => 'materialverbrauch.id',
+                                           'sql' => 'einsatz.id',
                                            'visible' => false,
                                            ),
+                             'datum' => array(
+                                           'name' => 'Datum',
+                                           'type' => 'date',
+                                           'width' => 70,
+                                           ),
                              'kostenstelle' => array(
-                                           'name' => 'KSt',
-                                           'width' => 50,
+                                           'name' => 'Kostenstelle',
+                                           'width' => 230,
+                                           'sql' => 'kostenstellen.kostenstelle',
+                                           ),
+                             'material' => array(
+                                           'name' => 'Material',
+                                           'width' => 70,
+                                           'control' => "new Rico.TableColumn.checkbox('t','f','0',true)",
+                                           'sql' => '(SELECT count(*) > 0 FROM materialverbrauch WHERE einsatz = einsatz.id)',
+                                           'specs' => "ClassName: 'aligncenter', canSort: false",
+                                           ),
+                             ),
+             'rows' => 20,
+             'edit_title' => 'Materialverbrauch vermerken',
+             'edit_table' => 'materialverbrauch',
+             'edit' => array(
+                             'einsatz' => array(
+                                           'name' => 'Einsatz',
+                                           'type' => 'hidden',
+                                           'size' => 10,
+                                           'sql' => 'id',
                                            ),
                              'material' => array(
                                            'name' => 'Material',
-                                           'sql' => 'materialien.material',
-                                           'width' => 200,
+                                           'type' => 'select',
+                                           'options' => 'SELECT id,material AS text FROM materialien ORDER BY text',
+                                           'onchange' => 'select_material(this)',
+                                           'sql' => false,
                                            ),
                              'menge' => array(
                                            'name' => 'Menge',
-                                           'type' => 'number',
-                                           'specs' => "decPlaces: 2, ClassName: 'alignright'",
-                                           'width' => 50,
+                                           'type' => 'decimal',
+                                           'size' => 10,
+                                           'comment' => ' <span id="edit_einheit"></span>',
+                                           'sql' => false,
+                                           'required' => true,
                                            ),
+                             ),
+             'info' => array(
                              'einheit' => array(
-                                           'name' => 'Einheit',
-                                           'type' => 'number',
-                                           'specs' => "ClassName: 'alignright'",
-                                           'width' => 50,
+                                           'sql' => 'SELECT einheiten.einheit FROM einheiten ' .
+                                                    'JOIN materialien ON materialien.einheit = einheiten.id ' .
+                                                    'WHERE materialien.id = {id}',
                                            ),
-                             'datum' => array(
-                                           'name' => 'Datum',
-                                           'type' => 'date',
-                                           'width' => 60,
-                                           ),
-                             ),
-             'rows' => 20,
+                                  ),
              );
 
 ?>