function render() { $active_worker = PortSensorApplication::getActiveWorker(); $translate = DevblocksPlatform::getTranslationService(); $visit = PortSensorApplication::getVisit(); $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $response = DevblocksPlatform::getHttpResponse(); $tpl->assign('request_path', implode('/', $response->path)); // View $sensorsView = Ps_AbstractViewLoader::getView(self::VIEW_ALL_SENSORS); if (null == $sensorsView) { $sensorsView = new Ps_SensorView(); $sensorsView->id = self::VIEW_ALL_SENSORS; $sensorsView->name = $translate->_('core.menu.sensors'); $sensorsView->renderLimit = 25; $sensorsView->renderPage = 0; $sensorsView->renderSortBy = SearchFields_Sensor::NAME; $sensorsView->renderSortAsc = 1; $sensorsView->params = array(SearchFields_Sensor::IS_DISABLED => new DevblocksSearchCriteria(SearchFields_Sensor::IS_DISABLED, '=', 0)); Ps_AbstractViewLoader::setView($sensorsView->id, $sensorsView); } /* * [TODO] This doesn't need to save every display, but it was possible to * lose the params in the saved version of the view in the DB w/o recovery. * This should be moved back into the if(null==...) check in a later build. */ $tpl->assign('response_uri', 'sensors'); // $quick_search_type = $visit->get('crm.opps.quick_search_type'); // $tpl->assign('quick_search_type', $quick_search_type); $tpl->assign('view', $sensorsView); $tpl->assign('view_fields', Ps_SensorView::getFields()); $tpl->assign('view_searchable_fields', Ps_SensorView::getSearchFields()); $tpl->display('file:' . $this->_TPL_PATH . 'sensors/index.tpl'); }
function showTabSensorsAction() { $visit = PortSensorApplication::getVisit(); $translate = DevblocksPlatform::getTranslationService(); $active_worker = PortSensorApplication::getActiveWorker(); $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); // Select tab // $visit->set(PortSensorVisit::KEY_HOME_SELECTED_TAB, 'sensors'); // My Notifications $sensorsView = Ps_AbstractViewLoader::getView(self::VIEW_ACTIVE_SENSORS); // $title = vsprintf($translate->_('home.my_notifications.view.title'), $active_worker->getName()); if (null == $sensorsView) { $sensorsView = new Ps_SensorView(); $sensorsView->id = self::VIEW_ACTIVE_SENSORS; // $sensorsView->name = $title; $sensorsView->renderLimit = 25; $sensorsView->renderPage = 0; $sensorsView->renderSortBy = SearchFields_Sensor::NAME; $sensorsView->renderSortAsc = 1; } // Overload criteria $sensorsView->name = 'Active Sensors'; $sensorsView->params = array(SearchFields_Sensor::IS_DISABLED => new DevblocksSearchCriteria(SearchFields_Sensor::IS_DISABLED, '=', 0)); /* * [TODO] This doesn't need to save every display, but it was possible to * lose the params in the saved version of the view in the DB w/o recovery. * This should be moved back into the if(null==...) check in a later build. */ Ps_AbstractViewLoader::setView($sensorsView->id, $sensorsView); $tpl->assign('view', $sensorsView); $tpl->display('file:' . $this->_TPL_PATH . 'home/tabs/sensors/index.tpl'); }
function viewSaveCustomizeAction() { $translate = DevblocksPlatform::getTranslationService(); @($id = DevblocksPlatform::importGPC($_REQUEST['id'])); @($columns = DevblocksPlatform::importGPC($_REQUEST['columns'], 'array', array())); @($num_rows = DevblocksPlatform::importGPC($_REQUEST['num_rows'], 'integer', 10)); $num_rows = max($num_rows, 1); // make 1 the minimum $view = Ps_AbstractViewLoader::getView($id); $view->doCustomize($columns, $num_rows); $active_worker = PortSensorApplication::getActiveWorker(); // Conditional Persist if (substr($id, 0, 5) == "cust_") { // custom workspace $list_view_id = intval(substr($id, 5)); // Special custom view fields @($title = DevblocksPlatform::importGPC($_REQUEST['title'], 'string', $translate->_('views.new_list'))); $view->name = $title; // Persist Object $list_view = new Model_WorklistView(); $list_view->title = $title; $list_view->columns = $view->view_columns; $list_view->num_rows = $view->renderLimit; $list_view->params = $view->params; $list_view->sort_by = $view->renderSortBy; $list_view->sort_asc = $view->renderSortAsc; DAO_Worklist::update($list_view_id, array(DAO_Worklist::VIEW_SERIALIZED => serialize($list_view))); } else { $prefs = new Ps_AbstractViewModel(); $prefs->class_name = get_class($view); $prefs->view_columns = $view->view_columns; $prefs->renderLimit = $view->renderLimit; $prefs->renderSortBy = $view->renderSortBy; $prefs->renderSortAsc = $view->renderSortAsc; DAO_WorkerPref::set($active_worker->id, 'view' . $view->id, serialize($prefs)); } Ps_AbstractViewLoader::setView($id, $view); $view->render(); }
function saveAddLanguagePanelAction() { $active_worker = PortSensorApplication::getActiveWorker(); // Make sure we're an active worker if (empty($active_worker) || empty($active_worker->id)) { return; } $codes = DAO_Translation::getDefinedLangCodes(); @($add_lang_code = DevblocksPlatform::importGPC($_REQUEST['add_lang_code'], 'string', '')); @($copy_lang_code = DevblocksPlatform::importGPC($_REQUEST['copy_lang_code'], 'string', '')); @($del_lang_ids = DevblocksPlatform::importGPC($_REQUEST['del_lang_ids'], 'array', array())); if (!empty($del_lang_ids)) { if (is_array($del_lang_ids)) { foreach ($del_lang_ids as $lang_id) { DAO_Translation::deleteByLangCodes($lang_id); } } } // Don't add blanks or the same language twice. if (!empty($add_lang_code) && !isset($codes[$add_lang_code])) { // English reference strings (to know our scope) $english_strings = DAO_Translation::getMapByLang('en_US'); $copy_strings = array(); // If we have a desired source language for defaults, load it. if (!empty($copy_lang_code)) { if (0 == strcasecmp('en_US', $copy_lang_code)) { $copy_strings = $english_strings; } else { $copy_strings = DAO_Translation::getMapByLang($copy_lang_code); } } // Loop through English strings for new language if (is_array($english_strings)) { foreach ($english_strings as $string_id => $src_en) { /* @var $src_en Model_Translation */ $override = ''; // If we have a valid source, copy its override or its default (in that order) @($copy_string = $copy_strings[$string_id]); if (is_a($copy_string, 'Model_Translation')) { $override = !empty($copy_string->string_override) ? $copy_string->string_override : $copy_string->string_default; } // Insert the new string as an override. Only official translations are defaults $fields = array(DAO_Translation::STRING_ID => $string_id, DAO_Translation::LANG_CODE => $add_lang_code, DAO_Translation::STRING_DEFAULT => '', DAO_Translation::STRING_OVERRIDE => $override); DAO_Translation::create($fields); } } } // If we added a new language then change the view to display it if (!empty($add_lang_code)) { $defaults = new Ps_AbstractViewModel(); $defaults->class_name = 'Ps_TranslationView'; $defaults->id = Ps_TranslationView::DEFAULT_ID; // Clear the existing view $view = Ps_AbstractViewLoader::getView(Ps_TranslationView::DEFAULT_ID, $defaults); $view->doResetCriteria(); // Set search to untranslated strings that aren't English $view->renderSortBy = SearchFields_Translation::STRING_ID; $view->renderSortAsc = true; $view->params = array(SearchFields_Translation::LANG_CODE => new DevblocksSearchCriteria(SearchFields_Translation::LANG_CODE, DevblocksSearchCriteria::OPER_EQ, $add_lang_code)); /* * If we didn't copy from another language, only show empty strings * which makes it easier to translate in the GUI. */ if (empty($copy_lang_code)) { $view->params[SearchFields_Translation::STRING_OVERRIDE] = new DevblocksSearchCriteria(SearchFields_Translation::STRING_OVERRIDE, DevblocksSearchCriteria::OPER_EQ, ''); } Ps_AbstractViewLoader::setView($view->id, $view); } self::_clearCache(); DevblocksPlatform::redirect(new DevblocksHttpResponse(array('setup', 'translations'))); }
/** * This method automatically fixes any cached strange options, like * deleted custom fields. * */ protected function _sanitize() { $fields = $this->getColumns(); $custom_fields = DAO_CustomField::getAll(); $needs_save = false; // Parameter sanity check if (is_array($this->params)) { foreach ($this->params as $pidx => $null) { if (substr($pidx, 0, 3) != "cf_") { continue; } if (0 != ($cf_id = intval(substr($pidx, 3)))) { // Make sure our custom fields still exist if (!isset($custom_fields[$cf_id])) { unset($this->params[$pidx]); $needs_save = true; } } } } // View column sanity check if (is_array($this->view_columns)) { foreach ($this->view_columns as $cidx => $c) { // Custom fields if (substr($c, 0, 3) == "cf_") { if (0 != ($cf_id = intval(substr($c, 3)))) { // Make sure our custom fields still exist if (!isset($custom_fields[$cf_id])) { unset($this->view_columns[$cidx]); $needs_save = true; } } } else { // If the column no longer exists (rare but worth checking) if (!isset($fields[$c])) { unset($this->view_columns[$cidx]); $needs_save = true; } } } } // Sort by sanity check if (substr($this->renderSortBy, 0, 3) == "cf_") { if (0 != ($cf_id = intval(substr($this->renderSortBy, 3)))) { if (!isset($custom_fields[$cf_id])) { $this->renderSortBy = null; $needs_save = true; } } } if ($needs_save) { Ps_AbstractViewLoader::setView($this->id, $this); } }
function showTabAlertsAction() { $translate = DevblocksPlatform::getTranslationService(); $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = $this->_TPL_PATH; $tpl->assign('path', $tpl_path); $active_worker = PortSensorApplication::getActiveWorker(); // $tpl->assign('worker', $worker); // View $alertsView = Ps_AbstractViewLoader::getView(self::VIEW_MY_ALERTS); if (null == $alertsView) { $alertsView = new Ps_AlertView(); $alertsView->id = self::VIEW_MY_ALERTS; $alertsView->name = $translate->_('preferences.tab.alerts'); $alertsView->renderLimit = 25; $alertsView->renderPage = 0; $alertsView->renderSortBy = SearchFields_Alert::POS; $alertsView->renderSortAsc = 0; $alertsView->params = array(); } $alertsView->name = 'Alerts: ' . $active_worker->getName(); $alertsView->params = array(SearchFields_Alert::IS_DISABLED => new DevblocksSearchCriteria(SearchFields_Alert::IS_DISABLED, '=', 0), SearchFields_Alert::WORKER_ID => new DevblocksSearchCriteria(SearchFields_Alert::WORKER_ID, '=', $active_worker->id)); Ps_AbstractViewLoader::setView($alertsView->id, $alertsView); //$tpl->assign('response_uri', 'preferences/alerts'); // $quick_search_type = $visit->get('crm.opps.quick_search_type'); // $tpl->assign('quick_search_type', $quick_search_type); $tpl->assign('view', $alertsView); $tpl->assign('view_fields', Ps_AlertView::getFields()); $tpl->assign('view_searchable_fields', Ps_AlertView::getSearchFields()); $tpl->display('file:' . $tpl_path . 'preferences/tabs/alerts.tpl'); }