Class: ContentSectionObject

Inherits:
Object
  • Object
show all
Includes:
DataFactory, Foundry, StringFactory, Workflows
Defined in:
lib/sambal-cle/data_objects/lesson.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Workflows

menu_link, #open_my_site_by_name, #reset

Constructor Details

#initialize(browser, opts = {}) ⇒ ContentSectionObject

Returns a new instance of ContentSectionObject.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sambal-cle/data_objects/lesson.rb', line 60

def initialize(browser, opts={})
  @browser = browser

  defaults = {
    :title=>random_alphanums,
    :copyright_status=>"Public Domain",
    :modality=>[:check_textual]
  }
  options = defaults.merge(opts)

  set_options(options)
  raise "Your modality variable must be an Array containing one or more keys\nthat match the checkbox methods, like this:\n[:uncheck_textual, :check_visual, :check_auditory]" unless @modality.class==Array
  raise "You must specify a Site for your Section" if @site==nil
  raise "You must specify a Module for your Section" if @module==nil
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def content_type
  @content_type
end

Returns the value of attribute copyright_status.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def copyright_status
  @copyright_status
end

#editor_contentObject

Returns the value of attribute editor_content.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def editor_content
  @editor_content
end

#file_descriptionObject

Returns the value of attribute file_description.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def file_description
  @file_description
end

#file_folderObject

Returns the value of attribute file_folder.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def file_folder
  @file_folder
end

#file_nameObject

Returns the value of attribute file_name.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def file_name
  @file_name
end

#file_pathObject

Returns the value of attribute file_path.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def file_path
  @file_path
end

#hrefObject

Returns the value of attribute href.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def href
  @href
end

#instructionsObject

Returns the value of attribute instructions.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def instructions
  @instructions
end

#modalityObject

Returns the value of attribute modality.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def modality
  @modality
end

#moduleObject

Returns the value of attribute module.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def module
  @module
end

#siteObject

Returns the value of attribute site.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def site
  @site
end

#titleObject Also known as: name

Returns the value of attribute title.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def title
  @title
end

#urlObject

Returns the value of attribute url.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def url
  @url
end

#url_descriptionObject

Returns the value of attribute url_description.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def url_description
  @url_description
end

#url_titleObject

Returns the value of attribute url_title.



56
57
58
# File 'lib/sambal-cle/data_objects/lesson.rb', line 56

def url_title
  @url_title
end

Instance Method Details

#createObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/sambal-cle/data_objects/lesson.rb', line 78

def create
  open_my_site_by_name @site
  lessons
  reset
  on_page Lessons do |page|
    page.open_lesson @module
  end
  on_page AddEditModule do |page|
    page.add_content_sections
  end
  on_page AddEditContentSection do |page|
    page.title.set @title
    page.instructions.set @instructions
    @modality.each do |content|
      page.send(content)
    end
    page.content_type.fit @content_type
  end

  on AddEditContentSection do |page| # Note we are reinstantiating the class here because of
                                     # an issue with Selenium Webdriver throwing a
                                     # WeakReference error, given the partial page reload.
                                     # TODO: Figure out if there's a better solution for this
    case @content_type
      when "Compose content with editor"
        page.enter_source_text page.content_editor, @editor_content
      when "Upload or link to a file"
        page.select_a_file
        on_page LessonAddAttachment do |add|
          add.upload_local_file @file_name, @file_path
          add.continue
        end
        page.file_description.set @file_description
      when "Link to new or existing URL resource on server"
        page.select_url
        on_page SelectingContent do |select|
          select.new_url.set @url
          select.url_title.set @url_title
          select.continue
        end
        page.url_description.set @url_description
      when "Upload or link to a file in Resources"
        page.select_or_upload_file
        on_page Resources do |add|
          add.open_folder @file_folder unless @file_folder == nil
          add.select_file @file_name
          add.continue
        end
      else
        raise "You have a typo in what you've specified for your Section's content type.\nIt must be one of the options contained in the dropdown."
    end
    page.copyright_status.select @copyright_status
    page.add
  end
  on ConfirmSectionAdd do |confirm|
    confirm.finish
  end
  on Lessons do |list|
    @href = list.href @title
  end
end

#edit(opts = {}) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/sambal-cle/data_objects/lesson.rb', line 140

def edit opts={}
  open_my_site_by_name @site
  lessons
  reset
  on Lessons do |list|
    list.check_section @title
    list.edit
  end
  on AddEditContentSection do |edit|
    edit.title.fit opts[:title]
    edit.instructions.fit opts[:instructions]
    if opts[:modality].class==Array
      opts[:modality].each do |item|
        edit.send(item)
      end
    end

    # TODO: Add code here for updating attached resources

    edit.enter_source_text(edit.content_editor, opts[:editor_content]) unless opts[:editor_content]==nil

    # TODO: Add code here for updating remaining variables

    edit.finish
  end
  set_options(opts)
end