Class: Platform::Developer::AppsController

Inherits:
BaseController show all
Defined in:
app/controllers/platform/developer/apps_controller.rb

Overview

– Copyright © 2011 Michael Berkovich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++

Instance Method Summary collapse

Methods inherited from BaseController

#mobile_device?, #platform_current_developer, #platform_current_user, #platform_current_user_is_admin?, #platform_current_user_is_developer?, #platform_current_user_is_guest?

Instance Method Details

#createObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/platform/developer/apps_controller.rb', line 50

def create
  if application.save
    application.store_icon(params[:new_icon]) unless params[:new_icon].blank?
    application.(params[:new_logo]) unless params[:new_logo].blank?
    
    trfn('{app_name} registered', 'Client application controller notice', :app_name => application.name)
    redirect_to(:action => :index, :id => application.id)
  else
    flash[:error] = application.errors.full_messages.join(', ')
    prepare_form
    render :action => :new
  end
end

#create_versionObject



70
71
72
73
74
75
# File 'app/controllers/platform/developer/apps_controller.rb', line 70

def create_version
  @page_title = tr('Version {app_name}', 'Client application controller title', :app_name => application.name)
  @current_app = Platform::Application.find(params[:id]) 
  @app = Platform::Application.new(@current_app.attributes)
  @languages = Tr8n::Language.locale_options
end

#deleteObject



116
117
118
119
120
# File 'app/controllers/platform/developer/apps_controller.rb', line 116

def delete
  application.destroy
  trfn('{app_name} has been removed.', 'Client application controller notice', :app_name => application.name)
  redirect_to :action => :index
end

#editObject



64
65
66
67
68
# File 'app/controllers/platform/developer/apps_controller.rb', line 64

def edit
  @page_title = tr('Edit {app_name}', 'Client application controller title', :app_name => application.name)
  application.touch
  @languages = Tr8n::Language.locale_options
end

#indexObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/platform/developer/apps_controller.rb', line 28

def index
  @app = Platform::Application.find_by_id(params[:id]) if params[:id]
  @app = nil unless @app and @app.developed_by?(Platform::Config.current_developer)

  @apps = Platform::Application.where("developer_id=? and parent_id is null", Platform::Config.current_developer.id).order("updated_at desc")
  unless @app
    @app = @apps.first if @apps.any?
  end  

  @menu_app = @app
  @menu_app = @app.parent if @app && @app.parent

  @page_title = tr('Application Details for {app_name}', 'Client application controller title', :app_name => @app.name) if @app
end

#newObject



43
44
45
46
47
48
# File 'app/controllers/platform/developer/apps_controller.rb', line 43

def new
  @page_title = tr('Register New Application', 'Client application controller title')
  
  application
  prepare_form
end

#reset_secretObject



122
123
124
125
126
# File 'app/controllers/platform/developer/apps_controller.rb', line 122

def reset_secret
  application.reset_secret!
  trfn('Secret for {app_name} has been reset.', 'Client application controller notice', :app_name => application.name)
  redirect_to :action => :index, :id => application.id 
end

#submitObject



128
129
130
131
132
# File 'app/controllers/platform/developer/apps_controller.rb', line 128

def submit
  application.state ||= "new"
  application.submit!
  redirect_to :action => :index, :id => application.id 
end

#updateObject



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/controllers/platform/developer/apps_controller.rb', line 102

def update
  if application.update_attributes(params[:application])
    application.store_icon(params[:new_icon]) unless params[:new_icon].blank?
    application.(params[:new_logo]) unless params[:new_logo].blank?
    
    trfn('{app_name} updated.', 'Client applicaiton controller notice', :app_name => application.name)
    redirect_to(:action => :index, :id => application.id)
  else
    flash[:error] = application.errors.full_messages.join(', ')
    prepare_form
    render :action => :edit
  end
end

#versionObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/platform/developer/apps_controller.rb', line 77

def version
  old_app = Platform::Application.find(params[:current_version_id])
  
  app = Platform::Application.create(params[:application].merge(:developer => Platform::Config.current_developer))
  if params[:new_icon].blank?
    app.update_attributes(:icon_id => old_app.icon_id)
  else
    app.store_icon(params[:new_icon])
  end

  if params[:new_logo].blank?
    app.update_attributes(:logo_id => old_app.logo_id)
  else
    app.(params[:new_logo])
  end

  old_app.children.each do |child_app|
    child_app.update_attributes(:parent_id => app.id)
  end
  
  old_app.update_attributes(:parent_id => app.id, :version => (old_app.version || 1.0))

  redirect_to(:action => :index, :id => app.id)
end