Class: Viewpoint::SPWS::Types::ListItem

Inherits:
Object
  • Object
show all
Includes:
Viewpoint::SPWS::Types
Defined in:
lib/viewpoint/spws/types/list_item.rb

Overview

This class represents a Sharepoint ListItem returned from the Lists Web Service

See Also:

Constant Summary

Constants included from Viewpoint::SPWS::Types

PRIORITY, STATUS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ws, list_id, xml) ⇒ ListItem

Returns a new instance of ListItem.

Parameters:

  • ws (Viewpoint::SPWS::Websvc::List)

    The webservice instance this ListItem spawned from

  • list_id (String)

    The list id that this item belongs to

  • xml (Nokogiri::XML::Element)

    the List element we are building from



31
32
33
34
35
36
37
# File 'lib/viewpoint/spws/types/list_item.rb', line 31

def initialize(ws, list_id, xml)
  @ws = ws
  @list_id = list_id
  @pending_updates  = [] # a place to store updates before #save! is called
  @update_keys      = {} # the variables to update after #save!
  parse_xml_fields(xml)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



24
25
26
# File 'lib/viewpoint/spws/types/list_item.rb', line 24

def body
  @body
end

#created_dateObject (readonly)

Returns the value of attribute created_date.



25
26
27
# File 'lib/viewpoint/spws/types/list_item.rb', line 25

def created_date
  @created_date
end

#due_dateObject (readonly)

Returns the value of attribute due_date.



25
26
27
# File 'lib/viewpoint/spws/types/list_item.rb', line 25

def due_date
  @due_date
end

#editorObject (readonly)

Returns the value of attribute editor.



24
25
26
# File 'lib/viewpoint/spws/types/list_item.rb', line 24

def editor
  @editor
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



24
25
26
# File 'lib/viewpoint/spws/types/list_item.rb', line 24

def file_name
  @file_name
end

#file_refObject (readonly)

Returns the value of attribute file_ref.



24
25
26
# File 'lib/viewpoint/spws/types/list_item.rb', line 24

def file_ref
  @file_ref
end

#guidObject (readonly)

Returns the value of attribute guid.



24
25
26
# File 'lib/viewpoint/spws/types/list_item.rb', line 24

def guid
  @guid
end

#idObject (readonly)

Returns the value of attribute id.



24
25
26
# File 'lib/viewpoint/spws/types/list_item.rb', line 24

def id
  @id
end

Returns the value of attribute link_title.



26
27
28
# File 'lib/viewpoint/spws/types/list_item.rb', line 26

def link_title
  @link_title
end

#modified_dateObject (readonly)

Returns the value of attribute modified_date.



25
26
27
# File 'lib/viewpoint/spws/types/list_item.rb', line 25

def modified_date
  @modified_date
end

#object_typeObject (readonly)

Returns the value of attribute object_type.



24
25
26
# File 'lib/viewpoint/spws/types/list_item.rb', line 24

def object_type
  @object_type
end

#percent_completeObject (readonly)

Returns the value of attribute percent_complete.



26
27
28
# File 'lib/viewpoint/spws/types/list_item.rb', line 26

def percent_complete
  @percent_complete
end

#priorityObject (readonly)

Returns the value of attribute priority.



26
27
28
# File 'lib/viewpoint/spws/types/list_item.rb', line 26

def priority
  @priority
end

#statusObject (readonly)

Returns the value of attribute status.



26
27
28
# File 'lib/viewpoint/spws/types/list_item.rb', line 26

def status
  @status
end

#titleObject (readonly)

Returns the value of attribute title.



26
27
28
# File 'lib/viewpoint/spws/types/list_item.rb', line 26

def title
  @title
end

Instance Method Details

#assign(user) ⇒ Object

TODO:

should I return the String representation of the user or the Types::User?

Assign this item to a user

Parameters:



158
159
160
161
162
163
164
165
166
# File 'lib/viewpoint/spws/types/list_item.rb', line 158

def assign(user)
  raise "There is already a pending assignment" if @update_keys[:@assigned_to]
  upd = { :id => @id, :command => 'Update',
    :AssignedTo => "#{user.id};##{user.}",
  }
  @pending_updates << upd
  @update_keys[:@assigned_to] = 'ows_AssignedTo'
  user
end

#assign!(user) ⇒ Object

Assign this item to a user

See Also:



170
171
172
173
# File 'lib/viewpoint/spws/types/list_item.rb', line 170

def assign!(user)
  assign(user)
  save!
end

#delete!Object

Delete this ListItem



63
64
65
66
67
# File 'lib/viewpoint/spws/types/list_item.rb', line 63

def delete!
  del = [{ :id => @id, :command => 'Delete',
    :file_ref => full_file_ref }]
  @ws.update_list_items(@list_id, :item_updates => del)
end

#rename(title) ⇒ Object

Set a new title for this Item

Parameters:

  • title (String)

    The new title



72
73
74
75
76
77
78
79
80
81
# File 'lib/viewpoint/spws/types/list_item.rb', line 72

def rename(title)
  raise "There is already a pending rename" if @update_keys[:@title]
  upd = { :id => @id, :command => 'Update',
    :title => title,
  }
  @pending_updates << upd
  @update_keys[:@title]       = 'ows_Title'
  @update_keys[:@link_title]  = 'ows_LinkTitle'
  title
end

#rename!(title) ⇒ Object

Set a new title for this Item

See Also:



85
86
87
88
# File 'lib/viewpoint/spws/types/list_item.rb', line 85

def rename!(title)
  rename(title)
  save!
end

#save!Object

Save any pending changes



40
41
42
43
44
45
46
47
48
# File 'lib/viewpoint/spws/types/list_item.rb', line 40

def save!
  return true if @pending_updates.empty?
  resp = @ws.update_list_items(@list_id, :item_updates => @pending_updates)
  # @todo check for success before emptying Arry
  update_local_vars resp[:update][0]
  @pending_updates.clear
  true
  resp
end

#set_percent_complete(pct) ⇒ Object

Set the percentage complete of this item.

Parameters:

  • pct (Fixnum)

    the percent complete of this item



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/viewpoint/spws/types/list_item.rb', line 134

def set_percent_complete(pct)
  if(!(0..100).include?(pct))
    raise "Invalid :percent_complete #{topts[:percent_complete]}"
  end
  raise "There is already a pending percent complete change" if @update_keys[:@percent_complete]

  upd = { :id => @id, :command => 'Update',
    :percent_complete => pct,
  }
  @pending_updates << upd
  @update_keys[:@percent_complete] = 'ows_PercentComplete'
  pct
end

#set_percent_complete!(pct) ⇒ Object

Set the percentage complete of this item.



150
151
152
153
# File 'lib/viewpoint/spws/types/list_item.rb', line 150

def set_percent_complete!(pct)
  set_percent_complete pct
  save!
end

#set_priority(priority) ⇒ Object

Set the priority of this Item

Parameters:

  • priority (Symbol)

    The new priority. It must be one of these values: :high, :normal, :low



93
94
95
96
97
98
99
100
101
102
# File 'lib/viewpoint/spws/types/list_item.rb', line 93

def set_priority(priority)
  raise "Invalid priority it must be one of: #{PRIORITY.keys.join(', ')}" unless PRIORITY[priority]
  raise "There is already a pending priority change" if @update_keys[:@priority]
  upd = { :id => @id, :command => 'Update',
    :priority => PRIORITY[priority],
  }
  @pending_updates << upd
  @update_keys[:@priority] = 'ows_Priority'
  priority
end

#set_priority!(priority) ⇒ Object

Set the priority of this Item

See Also:



106
107
108
109
# File 'lib/viewpoint/spws/types/list_item.rb', line 106

def set_priority!(priority)
  set_priority priority
  save!
end

#set_status(status) ⇒ Object

Set the status of this Item

Parameters:

  • status (Symbol)

    The new status. It must be one of these values: :not_started, :in_progress, :completed, :deferred, :waiting



114
115
116
117
118
119
120
121
122
123
# File 'lib/viewpoint/spws/types/list_item.rb', line 114

def set_status(status)
  raise "Invalid status it must be one of: #{STATUS.keys.join(', ')}" unless STATUS[status]
  raise "There is already a pending status change" if @update_keys[:@status]
  upd = { :id => @id, :command => 'Update',
    :status => STATUS[status],
  }
  @pending_updates << upd
  @update_keys[:@status] = 'ows_Status'
  status
end

#set_status!(status) ⇒ Object

Set the status of this Item

See Also:



127
128
129
130
# File 'lib/viewpoint/spws/types/list_item.rb', line 127

def set_status!(status)
  set_status(status)
  save!
end

#update! {|_self| ... } ⇒ Object

Pass a block of updates that will be committed in one transaction

Examples:

li.update! do |l|
  l.rename 'New Name'
  l.set_priority :low
  l.set_status :waiting
end

Yields:

  • (_self)

Yield Parameters:



57
58
59
60
# File 'lib/viewpoint/spws/types/list_item.rb', line 57

def update!
  yield self if block_given?
  save!
end