TRUE, 'templateadd'=>TRUE, 'templateedit'=>TRUE, 'templatelist'=>TRUE, ); public function action_ajaxtemplatetranslate() { $eto = ORM::factory('Email_Template',$this->request->param('id')); if (! $eto->loaded() OR ! $this->request->query('key')) { $output = _('Unable to find translate data'); } else { $eto = $eto->translate->where('language_id','=',$this->request->query('key'))->find(); $output = View::factory('email/admin/ajaxtemplatetranslate') ->set('o',$eto); } $this->template->content = $output; } /** * Add a template */ public function action_templateadd() { Block::factory() ->type('form-horizontal') ->title('Add Email Template') ->title_icon('icon-wrench') ->body($this->add_edit_template()); } /** * List our defined email templates */ public function action_templatelist() { Block::factory() ->title(_('System Emails Templates Available')) ->title_icon('icon-th') ->body(Table::factory() ->page_items(25) ->data(ORM::factory('Email_Template')->find_all()) ->columns(array( 'id'=>'ID', 'name'=>'Name', 'active'=>'Active', 'description'=>'Descrption', )) ->prepend(array( 'id'=>array('url'=>URL::link('admin','email/templateedit/')), )) ); } /** * Edit Template Definition * @todo Change this into an add_view function like payment() */ public function action_templateedit() { list($id,$output) = Table::page(__METHOD__); Block::factory() ->type('form-horizontal') ->title('Update Email Template') ->title_icon('icon-wrench') ->body($this->add_edit_template($id,$output)); } private function add_edit_template($id=NULL,$output='') { $eto = ORM::factory('Email_Template',$id); if ($this->request->post()) { // @todo To update the setup ID $eto->email_setup_id = '1'; if (! $this->save($eto)) $eto->reload(); } // @todo With tinymce, if the user reselects a different language, we loose the editor? Script::factory() ->type('stdin') ->data(' $(document).ready(function() { $("select[name=language_id]").change(function() { // If we select a blank, then dont continue if (this.value == 0) return false; // Send the request and update sub category dropdown $.ajax({ type: "GET", data: "key="+$(this).val(), dataType: "html", cache: false, url: "'.URL::link('admin','email/ajaxtemplatetranslate/'.$eto->id,TRUE).'", timeout: 2000, error: function(x) { alert("Failed to submit"); }, success: function(data) { $("div[id=translate]").empty().append(data); } }); }); }); '); return View::factory('email/admin/add_edit_template') ->set('o',$eto); $output .= Form::open(); $output .= View::factory($this->viewpath()); $output .= View::factory($this->viewpath().'/translate'); $output .= '