# encoding: utf-8

require_relative 'admin_page.rb'

class ItemTypes < AdminPage
  def visit
    @browser.goto intranet(:item_types)
    self
  end

  def show_all
    @browser.select_list(:name => "table_item_type_length").select_value("-1")
    self
  end

  def create(code, desc)
    @browser.execute_script("document.getElementById('newitemtype').click()")
    Watir::Wait.until {
      @browser.form(:id => "itemtypeentry").text_field(:id => "itemtype").present?
    }

    form = @browser.form(:id => "itemtypeentry")
    form.text_field(:id => "itemtype").set code
    form.text_field(:id => "description").set desc
    form.submit
    self
  end

  def delete(code)
    item_type_table.rows.each do |row|
      if row.text.include?(code)
        row.link(:href => /op=delete_confirm/).click
        @browser.input(:value => "Delete this Item Type").click
        break
      end
    end
  end

  def exists(code, desc)
    text = item_type_table.text
    text.should include(code)
    text.should include(desc)
    self
  end

  def item_type_table
    table =  @browser.table(:id => "table_item_type")
    table.wait_until_present
    table
  end

end
# encoding: utf-8

require_relative 'admin_page.rb'

class ItemTypes < AdminPage
  def visit
    @browser.goto intranet(:item_types)
    self
  end

  def show_all
    @browser.select_list(:name => "table_item_type_length").select_value("-1")
    self
  end

  def create(code, desc)
    @browser.execute_script("document.getElementById('newitemtype').click()")
    Watir::Wait.until {
      @browser.text_field(:id => "itemtype").present?
    }

    form = @browser.form(:id => "itemtypeentry")
    form.text_field(:id => "itemtype").set code
    form.text_field(:id => "description").set desc
    form.submit
    self
  end

  def delete(code)
    item_type_table.rows.each do |row|
      if row.text.include?(code)
        row.link(:href => /op=delete_confirm/).click
        @browser.input(:value => "Delete this Item Type").click
        break
      end
    end
  end

  def exists(code, desc)
    text = item_type_table.text
    text.should include(code)
    text.should include(desc)
    self
  end

  def item_type_table
    table =  @browser.table(:id => "table_item_type")
    table.wait_until_present
    table
  end

end
Add a new attempt at selecting only what we want directly
Add a new attempt at selecting only what we want directly
