7547f083ce5bb9db20090c48ee7f65ef1c865aee

Author: yandod

Date: 2009-12-26 18:08:06 +0900

finished enumerations destroy

diff --git a/app/controllers/enumerations_controller.php b/app/controllers/enumerations_controller.php index 4278b31..0ae043d 100644 --- a/app/controllers/enumerations_controller.php +++ b/app/controllers/enumerations_controller.php @@ -15,19 +15,7 @@ class EnumerationsController extends AppController { } -# -# def new -# @enumeration = Enumeration.new(:opt => params[:opt]) -# end -# function add(){ -# @enumeration = Enumeration.new(params[:enumeration]) -# if @enumeration.save -# flash[:notice] = l(:notice_successful_create) -# redirect_to :action => 'list', :opt => @enumeration.opt -# else -# render :action => 'new' -# end if ($this->data) { $listBehavior = ClassRegistry::getObject('ListBehavior'); $listBehavior->settings['Enumeration']['scope'] = "Enumeration.opt = '{$this->params['named']['opt']}'"; @@ -88,20 +76,21 @@ class EnumerationsController extends AppController { $enumeration = $this->Enumeration->find('first',$param); $this->set('options',$this->Enumeration->OPTIONS); $this->set('enumeration',$enumeration); - if (!$this->Enumeration->in_use($enumeration)) { + $count = $this->Enumeration->objects_count($enumeration); + $this->set('objects_count',$count); + if ($count == 0) { # No associated objects if ($this->Enumeration->del($id)){ $this->Session->setFlash(__('Successful update.', true), 'default', array('class'=>'flash flash_notice')); $this->redirect('index'); } } else if (isset($this->data['Enumeration']['reassign_to_id'])) { -# elsif params[:reassign_to_id] # if reassign_to = Enumeration.find_by_opt_and_id(@enumeration.opt, params[:reassign_to_id]) -# @enumeration.destroy(reassign_to) -# redirect_to :action => 'index' + $this->Enumeration->destroy($enumeration,$this->data['Enumeration']['reassign_to_id']); + $this->redirect('index'); # end } -# @enumerations = Enumeration.get_values(@enumeration.opt) - [@enumeration] + $this->set('enumerations',$this->Enumeration->get_values($enumeration['Enumeration']['opt'])); # #rescue # # flash[:error] = 'Unable to delete enumeration' # # redirect_to :action => 'index' diff --git a/app/locale/jpn/LC_MESSAGES/default.po b/app/locale/jpn/LC_MESSAGES/default.po index 413b586..b763cc9 100755 --- a/app/locale/jpn/LC_MESSAGES/default.po +++ b/app/locale/jpn/LC_MESSAGES/default.po @@ -1200,7 +1200,7 @@ msgstr "情報" # text_enumeration_category_reassign_to msgid "'Reassign them to this value:'" -msgstr "'次の値に割り当て直す:'" +msgstr "次の値に割り当て直す:" # setting_attachment_max_size msgid "Attachment max. size" @@ -1546,7 +1546,7 @@ msgstr "最近の接続" # text_enumeration_destroy_question msgid "'%d objects are assigned to this value.'" -msgstr "'%d個のオブジェクトがこの値に割り当てられています。'" +msgstr "%d個のオブジェクトがこの値に割り当てられています。" # label_file_added msgid "File added" diff --git a/app/models/enumeration.php b/app/models/enumeration.php index eae6b73..6d5d10f 100644 --- a/app/models/enumeration.php +++ b/app/models/enumeration.php @@ -20,9 +20,6 @@ class Enumeration extends AppModel "ACTI" => array('label' => 'Activities (time tracking)', 'model' => 'TimeEntry', 'foreign_key' => 'activity_id') ); # -# def self.get_values(option) -# find(:all, :conditions => {:opt => option}, :order => 'position') -# end function get_values($option, $order = 'ASC') { return $this->find('all', array('conditions'=>array('opt'=>$option), 'order'=>"position $order")); } @@ -49,17 +46,18 @@ class Enumeration extends AppModel function in_use($row){ return ($this->objects_count($row) != 0); } -# -# alias :destroy_without_reassign :destroy -# -# # Destroy the enumeration -# # If a enumeration is specified, objects are reassigned -# def destroy(reassign_to = nil) + + # alias :destroy_without_reassign :destroy + + # Destroy the enumeration + # If a enumeration is specified, objects are reassigned + function destroy($row,$reassign_to = null) { # if reassign_to && reassign_to.is_a?(Enumeration) -# OPTIONS[self.opt][:model].update_all("#{OPTIONS[self.opt][:foreign_key]} = #{reassign_to.id}", "#{OPTIONS[self.opt][:foreign_key]} = #{id}") + $model = ClassRegistry::init($this->OPTIONS[$row['Enumeration']['opt']]['model']); + $model->updateAll(aa($this->OPTIONS[$row['Enumeration']['opt']]['foreign_key'],$reassign_to),aa($this->OPTIONS[$row['Enumeration']['opt']]['foreign_key'],$row['Enumeration']['id'])); # end -# destroy_without_reassign -# end + $this->del($row['Enumeration']['id']); + } # # def <=>(enumeration) # position <=> enumeration.position diff --git a/app/views/enumerations/destroy.ctp b/app/views/enumerations/destroy.ctp index 7ecc760..9cd916d 100644 --- a/app/views/enumerations/destroy.ctp +++ b/app/views/enumerations/destroy.ctp @@ -1,10 +1,16 @@ <h2><?php __($options[$enumeration['Enumeration']['opt']]['label']) ?>: <?php echo h($enumeration['Enumeration']['name']) ?></h2> -<?php echo $form->create() ?> +<?php echo $form->create(null,aa('url',aa('action','destroy','id',$enumeration['Enumeration']['id']))) ?> <div class="box"> -<p><strong><?php echo sprintf(__("'%d objects are assigned to this value.'",true),100) ?></strong></p> +<p><strong><?php echo sprintf(__("'%d objects are assigned to this value.'",true),$objects_count) ?></strong></p> <p><?php __("'Reassign them to this value:'") ?> -<%= select_tag 'reassign_to_id', ("<option>--- #{l(:actionview_instancetag_blank_option)} ---</option>" + options_from_collection_for_select(@enumerations, 'id', 'name')) %></p> +<?php //<%= select_tag 'reassign_to_id', ("<option>--- #{l(:actionview_instancetag_blank_option)} ---</option>" + options_from_collection_for_select(@enumerations, 'id', 'name')) %> ?> +<?php +$reoptions = Set::combine($enumerations,'{n}.Enumeration.id','{n}.Enumeration.name'); +unset($reoptions[$enumeration['Enumeration']['id']]); +?> +<?php echo $form->select('reassign_to_id',$reoptions) ?> +</p> </div> <?php echo $form->submit(__('Apply',true)) ?>