Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAW - refactor catalog organizations forms #538

Merged
merged 12 commits into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 8 additions & 28 deletions app/controllers/catalog_manager/cores_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,21 @@
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class CatalogManager::CoresController < CatalogManager::AppController
layout false
respond_to :js, :html

class CatalogManager::CoresController < CatalogManager::OrganizationsController
def create
@program = Program.find(params[:program_id])
@core = Core.new({:name => params[:name], :abbreviation => params[:name], :parent_id => @program.id})
@core.build_subsidy_map()
@core.save

respond_with [:catalog_manager, @core]
@parent_org = Program.find(params[:program_id])
@organization = Core.new({name: params[:name], abbreviation: params[:name], parent_id: @parent_org.id})
super
end

def show
@core = Core.find(params[:id])
@core.setup_available_statuses
@path = catalog_manager_core_path
super
end

def update
@core = Core.find(params[:id])

unless params[:core][:tag_list]
params[:core][:tag_list] = ""
end

params[:core].delete(:id)
if @core.update_attributes(params[:core])
flash[:notice] = "#{@core.name} saved correctly."
else
flash[:alert] = "Failed to update #{@core.name}."
end

@core.setup_available_statuses
@entity = @core
respond_with @core, :location => catalog_manager_core_path(@core)
@attributes = params[:core]
super
end

end
34 changes: 7 additions & 27 deletions app/controllers/catalog_manager/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,19 @@
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class CatalogManager::InstitutionsController < CatalogManager::AppController
respond_to :js, :html, :json
layout false

class CatalogManager::InstitutionsController < CatalogManager::OrganizationsController
def create
@institution = Institution.create({:name => params[:name], :abbreviation => params[:name], :is_available => false})
@user.catalog_manager_rights.create :organization_id => @institution.id

respond_with [:catalog_manger, @institution]
@organization = Institution.create({name: params[:name], abbreviation: params[:name], is_available: false})
@user.catalog_manager_rights.create( organization_id: @organization.id )
end

def show
@institution = Institution.find(params[:id])
@institution.setup_available_statuses
@path = catalog_manager_institution_path
super
end

def update
@institution = Institution.find(params[:id])

unless params[:institution][:tag_list]
params[:institution][:tag_list] = ""
end

params[:institution].delete(:id)
if @institution.update_attributes(params[:institution])
@institution.update_descendants_availability(params[:institution][:is_available])
flash[:notice] = "#{@institution.name} saved correctly."
else
flash[:alert] = "Failed to update #{@institution.name}."
end

@institution.setup_available_statuses
@entity = @institution
respond_with @institution, :location => catalog_manager_institution_path(@institution)
@attributes = params[:institution]
super
end
end
79 changes: 79 additions & 0 deletions app/controllers/catalog_manager/organizations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright © 2011 MUSC Foundation for Research Development
# All rights reserved.

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class CatalogManager::OrganizationsController < CatalogManager::AppController
layout false
respond_to :js, :html, :json

def create
@organization.build_subsidy_map()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless is an institution

@organization.save
end

def show
@organization = Organization.find(params[:id])
@organization.setup_available_statuses
render 'catalog_manager/organizations/show'
end

def update
@organization = Organization.find(params[:id])
update_organization
save_pricing_setups
set_org_tags
@organization.setup_available_statuses
@entity = @organization
render 'catalog_manager/organizations/update'
end

private

def update_organization
@attributes.delete(:id)
if @organization.update_attributes(@attributes)
flash[:notice] = "#{@organization.name} saved correctly."
else
flash[:alert] = "Failed to update #{@organization.name}."
end
end

def save_pricing_setups
if params[:pricing_setups] && ['Program', 'Provider'].include?(@organization.type)
params[:pricing_setups].each do |ps|
if ps[1]['id'].blank?
ps[1].delete(:id)
ps[1].delete(:newly_created)
@organization.pricing_setups.build(ps[1])
else
# @organization.pricing_setups.find(ps[1]['id']).update_attributes(ps[1])
ps_id = ps[1]['id']
ps[1].delete(:id)
@organization.pricing_setups.find(ps_id).update_attributes(ps[1])
end
@organization.save
end
end
end

def set_org_tags
unless @attributes[:tag_list] || @organization.type == 'Institution'
@attributes[:tag_list] = ""
end
end
end
52 changes: 8 additions & 44 deletions app/controllers/catalog_manager/programs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,21 @@
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class CatalogManager::ProgramsController < CatalogManager::AppController
respond_to :js, :html, :json
layout false

class CatalogManager::ProgramsController < CatalogManager::OrganizationsController
def create
@provider = Provider.find(params[:provider_id])
@program = Program.new({:name => params[:name], :abbreviation => params[:name], :parent_id => @provider.id})
@program.build_subsidy_map()
@program.save

respond_with [:catalog_manager, @program]
@parent_org = Provider.find(params[:provider_id])
@organization = Program.new({name: params[:name], abbreviation: params[:name], parent_id: @parent_org.id})
super
end

def show
@organization = Organization.find params[:id]
@program = Program.find params[:id]
@program.setup_available_statuses
@path = catalog_manager_program_path
super
end

def update
@program = Program.find(params[:id])

unless params[:program][:tag_list]
params[:program][:tag_list] = ""
end

params[:program].delete(:id)

if @program.update_attributes(params[:program])
@program.update_descendants_availability(params[:program][:is_available])
flash[:notice] = "#{@program.name} saved correctly."
else
flash[:alert] = "Failed to update #{@program.name}."
end

params[:pricing_setups].each do |ps|
if ps[1]['id'].blank?
ps[1].delete(:id)
ps[1].delete(:newly_created)
@program.pricing_setups.build(ps[1])
else
ps_id = ps[1]['id']
ps[1].delete(:id)
@program.pricing_setups.find(ps_id).update_attributes(ps[1])
end
@program.save
end if params[:pricing_setups]

@program.setup_available_statuses
@entity = @program
respond_with @program, :location => catalog_manager_program_path(@program)
@attributes = params[:program]
super
end

end
51 changes: 8 additions & 43 deletions app/controllers/catalog_manager/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,21 @@
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class CatalogManager::ProvidersController < CatalogManager::AppController
respond_to :js, :html, :json
layout false

class CatalogManager::ProvidersController < CatalogManager::OrganizationsController
def create
@institution = Institution.find(params[:institution_id])
@provider = Provider.new({:name => params[:name], :abbreviation => params[:name], :parent_id => @institution.id})
@provider.build_subsidy_map()
@provider.save

respond_with [:catalog_manger, @provider]
@parent_org = Institution.find(params[:institution_id])
@organization = Provider.new({name: params[:name], abbreviation: params[:name], parent_id: @parent_org.id})
super
end

def show
@provider = Provider.find(params[:id])
@provider.setup_available_statuses
@path = catalog_manager_provider_path
super
end

def update
@provider = Provider.find(params[:id])

unless params[:provider][:tag_list]
params[:provider][:tag_list] = ""
end

params[:provider].delete(:id)
if @provider.update_attributes(params[:provider])
@provider.update_descendants_availability(params[:provider][:is_available])
flash[:notice] = "#{@provider.name} saved correctly."
else
flash[:alert] = "Failed to update #{@provider.name}."
end

params[:pricing_setups].each do |ps|
if ps[1]['id'].blank?
ps[1].delete(:id)
ps[1].delete(:newly_created)
@provider.pricing_setups.build(ps[1])
else
# @provider.pricing_setups.find(ps[1]['id']).update_attributes(ps[1])
ps_id = ps[1]['id']
ps[1].delete(:id)
@provider.pricing_setups.find(ps_id).update_attributes(ps[1])
end
@provider.save
end if params[:pricing_setups]

@provider.setup_available_statuses
@entity = @provider
respond_with @provider, :location => catalog_manager_provider_path(@provider)
@attributes = params[:provider]
super
end

end
2 changes: 2 additions & 0 deletions app/helpers/catalog_manager/organizations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CatalogManager::OrganizationsHelper
end