public function save(array $data, $type) { if (!DataCenterPage::userCan('change')) { return false; } switch ($type) { case 'location': $component = DataCenterDBLocation::newFromValues($data['row']); break; case 'space': $component = DataCenterDBSpace::newFromValues($data['row']); break; } if (isset($component)) { $component->save(); $component->saveMetaValues($data['meta']); $component->insertChange($data['change']); return true; } return false; }
public function edit($path) { // Detects mode if (!$path['id']) { // Creates a new facility location $location = DataCenterDBLocation::newFromValues(array('tense' => 'present', 'name' => DataCenterUI::message('default', 'new-type', DataCenterUI::message('type', 'location')))); // Sets 'do' specific parameters $formParameters = array('label' => 'add', 'success' => array('page' => 'facilities', 'type' => 'location'), 'type' => 'add'); $headingParameters = array('message' => 'adding-type', 'subject' => DataCenterUI::message('type', $path['type'])); } else { // Gets facility location from database $location = DataCenterDB::getLocation($path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'facilities', 'type' => 'location', 'action' => 'view', 'id' => $path['id']), 'type' => 'edit'); $headingParameters = array('message' => 'editing-type', 'subject' => DataCenterUI::message('type', $path['type'])); } // Builds JavaScript that hooks the button into the geocoder $jsForm = 'document.form_save'; $jsOut = DataCenterJs::callFunction('addHandler', array("{$jsForm}.field_button_0", DataCenterJs::toScalar('click'), DataCenterJs::buildFunction(null, DataCenterJs::chain(array('dataCenter.renderer.getTarget' => DataCenterJs::toScalar('map'), 'showAddress' => array('document.form_save.field_region.value', DataCenterJs::toObject(array('latField' => "'{$jsForm}.field_latitude'", 'lngField' => "'{$jsForm}.field_longitude'")))))))); // Complete form parameters $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'facilities', 'type' => 'location'), 'row' => $location, 'fields' => array('tense' => array('type' => 'tense', 'disable' => !$path['id'] ? array('past') : array()), 'name' => array('type' => 'string'), 'region' => array('type' => 'string'), array('type' => 'button', 'label' => 'lookup'), 'latitude' => array('type' => 'string'), 'longitude' => array('type' => 'string')))); // Returns 2 columm layout with a form and a map widget return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderWidget('map', !$path['id'] ? array() : array('location' => $location)))) . DataCenterXml::script($jsOut); }