Skip to content

Commit

Permalink
Form validation implementation version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ploubser committed Oct 19, 2010
1 parent 1603ce6 commit ac7ef91
Show file tree
Hide file tree
Showing 39 changed files with 158 additions and 208 deletions.
17 changes: 0 additions & 17 deletions app/controllers/canvas_controller.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/controllers/griditems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def load_board
tmp = p.split(/:/, 2)
@parameters[tmp[0]] = tmp[1]
end
RAILS_DEFAULT_LOGGER.debug @parameters.inspect
@position = [item.x_axis, item.y_axis]
@state = params[:state]
page.insert_html :bottom, :container, :partial => "item"
Expand Down
2 changes: 0 additions & 2 deletions app/models/canvas.rb

This file was deleted.

5 changes: 3 additions & 2 deletions app/views/griditems/_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


<%= @parameter_list = "" %>
<div class="item" id="item<%= @timestamp%>" style="height:<%= @dimentions[0]%>px;width:<%=@dimentions[1] %>px;border:solid 2px;postion:absolute;" onmousemove="enableEvents('item<%= @timestamp%>')" >
<%= render :partial => "griditems/plugins/#{@type.downcase}/#{@type.downcase}", :locals => {:parameters => @parameters}%>
<div class="item" id="item<%= @timestamp%>" style="height:<%= @dimentions[0]%>px;width:<%=@dimentions[1] %>px;border:solid 2px;position:absolute;" onmousemove="enableEvents('item<%= @timestamp%>')" >
<%= render :partial => "griditems/plugins/#{@type.downcase}/#{@type.downcase}", :locals => {:parameters => @parameters, :itemid => "item" + @timestamp}%>
<%= javascript_tag "positionItem('item#{@timestamp}', 100 , 100)" %>
<%= form_tag 'index' %>
<% @parameters.each do |p| %>
<% unless p.to_s =~/.*authenticity.*|.*action.*|.*controller.*|.*height.*|.*refresh_rate.*|.*width.*|.*create.*|.*type.*|.*title.*|.*update.*/ %>
Expand Down
24 changes: 0 additions & 24 deletions app/views/griditems/edit.html.erb

This file was deleted.

8 changes: 0 additions & 8 deletions app/views/griditems/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<%= javascript_include_tag :defaults %>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script src="http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js" type="text/javascript"></script>

<% javascripts = get_javascript %>
<% javascripts.each do |javascript| %>
Expand All @@ -12,13 +11,8 @@
<%= stylesheet_link_tag "#{stylesheet}" %>
<% end %>

<%#= stylesheet_link_tag "jquery-ui-1.8.4.custom.css" %>
<%#= stylesheet_link_tag "bernard.css" %>

<%= javascript_tag "jQuery.noConflict();" %>



<div class="ui-widget ui-widget-content screen" id="screen">

<div class="ui-widget-header"><center>BernardBoard</center></div>
Expand Down Expand Up @@ -95,8 +89,6 @@
</div>
</div>
<% end %>

<div id="footer" class="footer ui-widget-header"><center>Pinetecltd - August 2010</center></div>
</div>
</div>
<% unless @fullscreen.nil?%>
Expand Down
23 changes: 0 additions & 23 deletions app/views/griditems/new.html.erb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
User name: <%= text_field_tag "usrname", "", :size=>24 %><br>
Password : <%= text_field_tag "passwrd" %> <bR>
Refresh Rate (in seconds): <%= text_field_tag "refresh_rate" %> <br>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"}%> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"} %>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"}, :condition => "validateForm()"%> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"}, :condition => "validateForm()"%>
<% end %>
42 changes: 23 additions & 19 deletions app/views/griditems/plugins/feed/_feed.html.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
<% feed = get_feed(@parameters["url"])%>

<div class="ui-widget">
<div class="ui-widget-header">
<%= @parameters["title"] %>
</div>
<% feed = get_feed(@parameters["uri"])%>
<% if feed == "error" %>
<%= javascript_tag "alert('Could not create Feed item. Please check if the feed url is correct.')"%>
<%= javascript_tag "jQuery('##{itemid}').remove();" %>
<% else %>
<div class="ui-widget">
<div class="ui-widget-header">
<%= @parameters["title"] %>
</div>

<% feed.items.each_with_index do |topic,i| %>
<div id="feed<%=i%>" class="feed" style="display:none;">
<div id="feed-header<%=i%>"
<%= image_tag "rss_icon.gif", :html => {"align" => "left"}%>
<%= topic.title %><br>
<small> Added on <%= topic.date.strftime('%m/%d/%Y')%> </small>
<HR>
</div>
<% feed.items.each_with_index do |topic,i| %>
<div id="feed<%=i%>" class="feed" style="display:none;">
<div id="feed-header<%=i%>"
<%= image_tag "rss_icon.gif", :html => {"align" => "left"}%>
<%= topic.title %><br>
<small> Added on <%= topic.date.strftime('%m/%d/%Y')%> </small>
<HR>
</div>

<div id="feed-description<%=i%>"><%= topic.description.gsub(/<[^>]+>/,"").squeeze(" ").strip %></div>
</div>
<% end %>
</div>
<div id="feed-description<%=i%>"><%= topic.description.gsub(/<[^>]+>/,"").squeeze(" ").strip %></div>
</div>
<% end %>
</div>

<%= javascript_tag "update_feed(#{feed.items.size})"%>
<%= javascript_tag "update_feed(#{feed.items.size})"%>
<% end %>

6 changes: 3 additions & 3 deletions app/views/griditems/plugins/feed/_formfor_feed.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Title : <%= text_field_tag "title" %><br>
Width : <%= text_field_tag "width", "", :size=>4%><br>
Height: <%= text_field_tag "height", "", :size=>4%><br>
RSS url: <%= text_field_tag "url", "", :size=>24 %><br>
RSS url: <%= text_field_tag "uri", "", :size=>24 %><br>
<%= hidden_field_tag "refresh_rate", "0" %>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"} %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"} %>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"}, :condition => "validateForm()" %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"}, :condition => "validateForm()" %>
<% end %>
4 changes: 2 additions & 2 deletions app/views/griditems/plugins/gauge/_formfor_gauge.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<%= observe_field :remote, :function => "jQuery('#gauge_remote_url').toggle()" %>
Path: <%= text_field_tag "path", "", :size=>24 %><br>
Refresh: <%= text_field_tag "refresh_rate"%><br>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"} %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"} %>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"}, :condition => "validateForm()" %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"} :condition => "validateForm()"%>
<% end %>
4 changes: 2 additions & 2 deletions app/views/griditems/plugins/image/_formfor_image.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<%=observe_field :remote, :function => "jQuery('#image_remote_url').toggle()" %>
Image location: <%= text_field_tag "image", "", :size=>24 %><br>
Refresh Rate (in seconds): <%= text_field_tag "refresh_rate" %> <br>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"}%> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"} %>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"}, :condition => "validateForm()"%> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"}, :condition => "validateForm()" %>
<% end %>
4 changes: 2 additions & 2 deletions app/views/griditems/plugins/nagios/_formfor_nagios.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
Nagios User Name : <%= text_field_tag "username"%> <br>
Nagios Password : <%= text_field_tag "password"%> <br>
Refresh (in seconds): <%= text_field_tag "refresh_rate", "", :size=>10, :id => "height" %> <br>
<%= submit_to_remote "create_grid_item", "Update", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"} %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"} %>
<%= submit_to_remote "create_grid_item", "Update", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"}, :condition => "validateForm()" %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"}, :condition => "validateForm()" %>
<% end %>
6 changes: 3 additions & 3 deletions app/views/griditems/plugins/twitter/_formfor_twitter.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Following? : <%= text_field_tag "title" %><br>
Width : <%= text_field_tag "width", "", :size=>4%><br>
Height: <%= text_field_tag "height", "", :size=>4%><br>
Feed uri: <%= text_field_tag "url", "", :size=>24 %><br>
Feed uri: <%= text_field_tag "uri", "", :size=>24 %><br>
<%= hidden_field_tag "refresh_rate", "0"%>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"} %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"} %>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"}, :condition => "validateForm()" %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"}, :condition => "validateForm()" %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/griditems/plugins/twitter/_twitter.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Since the twitter plugin is so closely related to the feed plugin, we're using the feed helper get_feed in both plugins, even tho it is only listed in feed.rb-->
<% feed = get_feed(@parameters["url"])%>
<% feed = get_feed(@parameters["uri"])%>

<div class="ui-widget">
<div class="ui-widget-header">
Expand Down
1 change: 0 additions & 1 deletion app/views/griditems/save_state.html.erb

This file was deleted.

18 changes: 0 additions & 18 deletions app/views/griditems/show.html.erb

This file was deleted.

5 changes: 5 additions & 0 deletions lib/generators/board_plugin/board_plugin_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ def manifest

end
end

protected
def banner
"Usage: #{$0} board_plugin plugin_name"
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% form_remote_tag :html => { :action => url_for(:controller => "griditems", :action =>"create_grid_item"), :id => "form_for"} do %>
<% form_remote_tag :html => { :action => url_for(:controller => "griditems", :action =>"create_grid_item"), :id => "form_for"} do %>"
<! -- Required form elements -->
Title : <%= text_field_tag "title" %> <br>
Width : <%= text_field_tag "width", "", :size=>4%><br>
Expand All @@ -7,6 +7,6 @@
<!-- Your form content goes here -->

<! -- Required submit buttons -->
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"} %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"} %>
<%= submit_to_remote "create_grid_item", "Create", :url => {:action => "create_grid_item", :type => type}, :html => {:class => "create"}, :condition => "" %> <br>
<%= submit_to_remote "update_grid_item", "Update", :url => {:action => "update_grid_item", :type => type}, :html => {:class => "update"}, :condition => ""%>
<% end %>
Binary file removed public/gauge.tgz
Binary file not shown.
89 changes: 56 additions & 33 deletions public/javascripts/bernard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,40 @@ jQuery(document).ready(function() {
}
);
jQuery('#type').change(); //Need the onchange event on page load to load a form for the initial selected plugin type
jQuery("#deleteitem").click(function(e){
jQuery(lastTarget).remove();
jQuery("#vmenu").toggle();

});

jQuery("#edititem").click(function(e){
centerPopup('popup');
loadPopup('popup');
form = document.getElementById('select_form');
type = jQuery(lastTarget).data('data').type
for(var i=0; i < form.type.length; i++){
if(form.type[i].value == type.capitalize()){
form.type[i].selected = true;
}
}
type = document.getElementById(form.type.id)
jQuery(type).change();
alert("Loading item ->" + jQuery(lastTarget).data('data').title);
jQuery('.create').hide();
jQuery('.update').show();
jQuery('#form_for input[name=title]').val(jQuery(lastTarget).data('data').title);
jQuery('#form_for input[name=height]').val(jQuery(lastTarget).height());
jQuery('#form_for input[name=width]').val(jQuery(lastTarget).width());
jQuery('#form_for input[name=refresh_rate]').val(jQuery(lastTarget).data('data').refresh_rate);
var paramArray = jQuery(lastTarget).data('data').params.split(";");

for(var i = 0; i < paramArray.length; i++) {
var ithParam = paramArray[i].split(":");
jQuery('#form_for input[name=' + ithParam[0] + ']').val(ithParam[1]);
jQuery("#deleteitem").click(function(e){
jQuery(lastTarget).remove();
jQuery("#vmenu").toggle();
jQuery('#results-content').empty();
});

jQuery("#edititem").click(function(e){
centerPopup('popup');
loadPopup('popup');
form = document.getElementById('select_form');
type = jQuery(lastTarget).data('data').type
for(var i=0; i < form.type.length; i++){
if(form.type[i].value == type.capitalize()){
form.type[i].selected = true;
}

});
}
type = document.getElementById(form.type.id)
jQuery(type).change();
alert("Loading item ->" + jQuery(lastTarget).data('data').title);
jQuery('.create').hide();
jQuery('.update').show();
jQuery('#form_for input[name=title]').val(jQuery(lastTarget).data('data').title);
jQuery('#form_for input[name=height]').val(jQuery(lastTarget).height());
jQuery('#form_for input[name=width]').val(jQuery(lastTarget).width());
jQuery('#form_for input[name=refresh_rate]').val(jQuery(lastTarget).data('data').refresh_rate);
var paramArray = jQuery(lastTarget).data('data').params.split(";");

for(var i = 0; i < paramArray.length; i++) {
var ithParam = paramArray[i].split(":");
jQuery('#form_for input[name=' + ithParam[0] + ']').val(ithParam[1]);
}

});

jQuery(document).click(function() {
jQuery("#vmenu").hide();
Expand Down Expand Up @@ -119,8 +120,7 @@ function enableEvents(e) {
item = document.getElementById(e)
display = document.getElementById('results-content')

display.innerHTML = 'Object name : ' + e + '<br>'
+ 'x-axis : ' + jQuery(item).offset().left + '<br>'
display.innerHTML = 'x-axis : ' + jQuery(item).offset().left + '<br>'
+ 'y-axis : ' + jQuery(item).offset().top + '<br>'
+ 'Height : ' + (Element.getHeight(item) - 4) + '<br>'
+ 'Width : ' + (Element.getWidth(item) - 4) + '<br>'
Expand Down Expand Up @@ -219,3 +219,26 @@ function positionItem(item, x, y){
i = document.getElementById(item)
jQuery(i).offset({top : y, left : x })
}

//Validate general form fields.
//Annonymous function is behaving strangely. Return is not terminating function. Look at that.
function validateForm(){
var returnValue = true;
jQuery(':input', '#form_for').each(function(){
if(this.value == ""){
alert("Please complete all fields.");
returnValue = false;
return false;
}
});

if(isNaN(jQuery('#form_for input[name=width]').val())){
alert("Width must be a integer value.");
returnValue = false;
}
if(isNaN(jQuery('#form_for input[name=height]').val())){
alert("Height must be a integer value.");
returnValue = false;
}
return returnValue;
}
Loading

0 comments on commit ac7ef91

Please sign in to comment.