/**
  *
  * @service template write
  * @param $fields
  * @return Gpf_Rpc_Form
  */
 public function save(Gpf_Rpc_Params $params)
 {
     $form = new Gpf_Rpc_Form($params);
     $templateName = $form->getFieldValue("templatename");
     $templateContent = $form->getFieldValue('templatecontent');
     try {
         $panelName = $form->getFieldValue('panelname');
     } catch (Gpf_Data_RecordSetNoRowException $e) {
         $panelName = '';
     }
     try {
         $theme = $form->getFieldValue('theme');
     } catch (Gpf_Data_RecordSetNoRowException $e) {
         $theme = trim(Gpf_Paths::DEFAULT_THEME, '/');
     }
     $template = new Gpf_Templates_Template($this->fixTemplateName($templateName), $panelName, Gpf_Templates_Template::FETCH_FILE, $theme);
     try {
         $template->saveTemplateToFile($templateContent);
     } catch (Gpf_Exception $e) {
         $form->setErrorMessage($this->_("Unable to save template '%s'", $templateName . " EXCEPTION: " . $e));
     }
     $form->setInfoMessage($this->_("Template '%s' saved", $templateName));
     return $form;
 }