Class Checkout
In: app/models/checkout.rb
Parent: ActiveRecord::Base

A Checkout is a working copy (Version) of a Page created so that it can be edited. The HTML to create the version is typically copied from the source version but it is also possible to provide it using the parameter :html

More information:

Copyright (c) 2006 Logica

Methods

Constants

HTML_START_ELEMENT = /<html([^\<])*/

Attributes

html  [RW] 
note  [RW]  Note supplied with checkout will be used to create Version.note
source_version  [RW]  Version we are checking out

Public Instance methods

[Source]

     # File app/models/checkout.rb, line 97
 97:   def before_validation_on_create
 98:     logger.info("Before validation on create of checkout for #{self.page.presentation_name}")
 99:     raise "Versions can only be created in Wiki sites" if !self.site.wiki?
100:     raise "Cannot create a checkout, a checkout already exists" if self.page.checkout 
101:     
102:     self.source_version = self.page.current_version if self.source_version.nil?
103:     
104:     logger.debug("Creating version for checkout")
105:     self.version = UserVersion.new(:wiki => self.site, :page => self.page, :user => self.user, :source_version => self.source_version)
106:     self.version.rel_path = "#{self.page.rel_path}_EPFWIKI_co.html"    
107:     File.makedirs(File.dirname(self.version.path))
108:     self.version.note = self.note
109:     # Method #prepare_for_edit is used to prepare the file for editing in 
110:     # the HTML editor that runs in the browser:
111:     # 1. onload event is removed from the body element
112:     # 2. Javascript lib treebrowser.js that chrashes the editor is replaced by a placeholder comment tag
113:     # 3. the EPF iframe element is removed
114:     # 4. the copyright_tag is replaced by a placeholder tag # DISABLED, didn't work after upgrade of EPF
115:     # 5. head tag is removed, because this TinyMCE cannot (and should not) manage this (this was BUG 96 - Doubling meta-tags)
116:     # 
117:     # See also #Page.before_create 
118:     #-- 
119:     # TODO step 4 does not seem to work anymore with current version of OpenUP (EPF) 
120:     # TODO move to version as part of checkout
121:     #++ 
122:     h = self.html # TODO is this right? document this
123:     h = self.source_version.html if h.blank?
124:     h = h.gsub(Page::BODY_TAG_PATTERN, '<body>') # 1
125:     h = h.gsub(Page::TREEBROWSER_PATTERN, Page::TREEBROWSER_PLACEHOLDER) # 2
126:     #html = html.gsub(COPYRIGHT_PATTERN, COPYRIGHT_PLACEHOLDER) # 4
127:     h = h.gsub(Page::HEAD_PATTERN, '') # 5
128:     self.version.html = h
129:   end

[Source]

    # File app/models/checkout.rb, line 47
47:   def checkin(user, h = nil)
48:     logger.info("Checkin of version #{self.version.path}")
49:     raise 'Cannot checkin, checked is not owned by user' if user != self.user && !user.cadmin?
50:     h = self.version.html if h.nil?
51: 
52:     # reset current attribute if set on a version
53:     cv = self.page.current_version 
54:     if !cv.nil? && cv.current
55:       cv.current = false
56:       cv.save!
57:     end
58:     Notification.find_or_create(self.page, self.user, Page.name)
59:     old_path = self.version.path
60:     self.version.version = self.page.max_version_no + 1
61:     self.version.rel_path = "#{self.page.rel_path}_EPFWIKI_v#{self.version.version}.html"
62:     logger.info("Moving version file from #{old_path} to #{self.version.path}")
63:     File.move(old_path, self.version.path)
64:     self.version.save!
65:     
66:     # Correct head tag of version file
67:     # TODO rename HEAD_PATTERN -> HEAD_REGEXP
68:     unless h.index(Page::HEAD_PATTERN).nil?
69:       logger.info("Head element found, replacing it with head element of original page")
70:       h = h.gsub(Page::HEAD_PATTERN, self.page.head_tag)
71:     else
72:       unless h.index(HTML_START_ELEMENT).nil?
73:         logger.info("HTML element found, adding a head element to it")
74:         h = h.gsub(HTML_START_ELEMENT, HTML_START_ELEMENT.match(h)[0] + self.page.head_tag)
75:       else
76:         logger.info("No head or html element found, adding head element and letting tidy do the rest")
77:         h = self.page.head_tag + h
78:       end
79:     end
80:     logger.info("Removing EPF Wiki Javascript library includes")
81:     h = h.gsub(Page::PAGE_HEAD_SNIPPET_PATTERN,'') if h.index(Page::PAGE_HEAD_SNIPPET_PATTERN)
82:     self.version.html = h
83:     
84:     # copy version to page and enhance
85:     self.page.html = self.version.html
86:     Page.enhance_file(self.page.path) 
87:     h= self.page.html
88:     h = h.gsub(Page::BODY_TAG_PATTERN, self.page.body_tag ) if self.page.body_tag
89:     h = h.gsub(Page::TREEBROWSER_PLACEHOLDER, self.page.treebrowser_tag) if self.page.treebrowser_tag
90:     h = h.gsub(Page::COPYRIGHT_PLACEHOLDER, self.page.copyright_tag) if self.page.copyright_tag
91:     h = h.gsub('class="pageTitle"', 'nowrap="true" class="pageTitle"') # TODO workaround for 250148: No-wrap should be part of CSS file https://bugs.eclipse.org/bugs/show_bug.cgi?id=250148
92:     self.page.html = h
93:     # TODO set title equal to pageTitle? 
94:     self.destroy
95:   end

[Source]

    # File app/models/checkout.rb, line 40
40:   def undo
41:     logger.info("Undo of checkout #{self.id}")
42:     self.version.destroy
43:     self.page.destroy if self.page.versions.size == 0 # If no versions remain, this must be a new page, so we also remove the page
44:     self.destroy
45:   end

[Source]

     # File app/models/checkout.rb, line 131
131:   def validate_on_create
132:     logger.debug('validate_on_create')
133:     errors.add(:site, 'can\'t be a baseline process') if self.site.baseline_process?
134:   end

[Validate]