Class: AdminController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::FILE_TYPES

Instance Method Summary collapse

Methods inherited from ApplicationController

wiki, wiki=

Instance Method Details

#create_systemObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/admin_controller.rb', line 7

def create_system
  if @wiki.setup?
    flash[:error] = "        Wiki has already been created in '\#{@wiki.storage_path}'. Shut down Instiki and delete \n        this directory if you want to recreate it from scratch.<br/><br/>\n        (WARNING: this will destroy content of your current wiki).\n    EOL\n    redirect_home(@wiki.webs.keys.first)\n  elsif @params['web_name']\n    # form submitted -> create a wiki\n    @wiki.setup(@params['password'], @params['web_name'], @params['web_address']) \n    flash[:info] = <<-EOL\n        Your new wiki '\#{@params['web_name']}' is created!<br/>\n        Please edit its home page and press Submit when finished.\n    EOL\n    redirect_to :web => @params['web_address'], :controller => 'wiki', :action => 'new', \n        :id => 'HomePage'\n  else\n    # no form submitted -> go to template\n  end\nend\n"

#create_webObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/admin_controller.rb', line 29

def create_web
  if @params['address']
    # form submitted

    if @wiki.authenticate(@params['system_password'])
      begin
        @wiki.create_web(@params['name'], @params['address'])
        flash[:info] = "New web '#{@params['name']}' successfully created."
        redirect_to :web => @params['address'], :controller => 'wiki', :action => 'new', 
            :id => 'HomePage'
      rescue Instiki::ValidationError => e
        flash[:error] = e.message
        # and re-render the form again

      end
    else 
      redirect_to :controller => 'wiki', :action => 'index'
    end
  else
    # no form submitted -> render template

  end
end

#edit_webObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/admin_controller.rb', line 50

def edit_web
  system_password = @params['system_password']
  if system_password
    # form submitted

    if wiki.authenticate(system_password)
      begin
        wiki.edit_web(
          @web.address, @params['address'], @params['name'], 
          @params['markup'].intern, 
          @params['color'], @params['additional_style'], 
          @params['safe_mode'] ? true : false, 
          @params['password'].empty? ? nil : @params['password'],
          @params['published'] ? true : false, 
          @params['brackets_only'] ? true : false,
          @params['count_pages'] ? true : false,
          @params['allow_uploads'] ? true : false,
          @params['max_upload_size']
        )
        flash[:info] = "Web '#{@params['address']}' was successfully updated"
        redirect_home(@params['address'])
      rescue Instiki::ValidationError => e
        flash[:error] = e.message
        # and re-render the same template again

      end
    else
      flash[:error] = password_error(system_password)
      # and re-render the same template again

    end
  else
    # no form submitted - go to template

  end
end

#remove_orphaned_pagesObject



83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/admin_controller.rb', line 83

def remove_orphaned_pages
  if wiki.authenticate(@params['system_password_orphaned'])
    wiki.remove_orphaned_pages(@web_name)
    flash[:info] = 'Orphaned pages removed'
    redirect_to :controller => 'wiki', :web => @web_name, :action => 'list'
  else
    flash[:error] = password_error(@params['system_password'])
    return_to_last_remembered
  end
end