ref: refs/heads/master
commit 46ef514f1a447fcd6161aa5ac433e6723c0e6315
Author: Ladislav Slezak #{html_edit_link(item.send(permissions[:id]))}</td>"
+ end
+
+ if permissions[:delete]
+ line += " #{html_delete_link(item.send(permissions[:id]))}</td>"
+ end
+
+ ret += "<tr>#{line}</tr>"
+ end
+
+ return ret
+ end
+
+ ##
+ # Create a simple HTML table
+ #
+ # Parameters:
+ # * labels - an array of strings - table headings
+ # * items - an array of objects - table content
+ # * properties - an array of strings - name of the method which will be called for the respective column.
+ # The result will be displayed in the table.
+ # * permissions - a hash with permissions - used to display/hide Add, Edit, and Delete buttons.
+ # The argument is optional, if missing no button will be displayed. Expected keys are :add, :edit, :delete.
+ # If a key is missing or the value is false the relevant button is hidden.
+ # * optional block with two arguments: object and column number - this block is used
+ # for computing table values for columns with property method set to nil. See the example.
+ # Use the column block parameter to distinguish the columns if there are several columns with nil property.
+ #
+ # Examples:
+ #
+ # <tt>simple_table([_("First Name"), _("Surname")], @users, [:first_name, :surname], {:add => true, :edit => true, :delete => true, :id => :name})</tt>
+ #
+ # <tt>simple_table([_("Avg. Download Speed")], files, [nil]){|file, column| "#{file.size/file.download_time/1024} kB/s"}</tt>
+ #
+ def html_simple_table(labels, items, properties, permissions = {}, &block)
+ header = ''
+
+ labels.each { |l|
+ header += " #{h(l)}</th>"
+ }
+
+ if permissions[:edit]
+ header += " #{h(label_edit)}</th>"
+ end
+
+ if permissions[:delete]
+ header += " #{h(label_delete)}</th>"
+ end
+
+ content = html_create_table_content(items, properties, permissions, block)
+
+ ret = " <tr>#{header}</tr>#{content}</table>"
+
+ ret += "<br>" + button_to(label_add, {:action => "new"}) if permissions[:add]
+
+ return ret
+ end
+
+end
+
+# vim: ft=ruby
diff --git a/webclient/app/helpers/view_helpers/label_helper.rb b/webclient/app/helpers/view_helpers/label_helper.rb
new file mode 100644
index 0000000..06a925c
--- /dev/null
+++ b/webclient/app/helpers/view_helpers/label_helper.rb
@@ -0,0 +1,16 @@
+
+module ViewHelpers::LabelHelper
+ include GetText
+
+ def label_add
+ return _("Add")
+ end
+
+ def label_edit
+ return _("Edit")
+ end
+
+ def label_delete
+ return _("Delete")
+ end
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org