Please help me DRY my script

Hi there guys,
I am struggling with a script for a number of reasons. Firstly it is
really ugly… i mean REALLY ugly. Strangely it does not display
properly in Internet Explorer, and i don’t know why, the JavaScript does
not seem to take affect in IE.

Anything you guys could do to help me make this better would be great (i
mean lets face it any improvement would be better than no improvement)!


<%- @title = "Write entry" -%>

<div id="entries_write" class="content edit">


<h2><img src="/blog/images/writersicon.png" alt="An image of a
clipboard">  <% if @entry.nil?%>Write a new article! <% else %>
<%= @entry.title %><% end %></h2>


<%= form_tag({:action => "save"} ,{:id =>"live-entry-form"}, {:method =>
"post", :multipart => true}) %>
<h8><a href="#" id="reveal"
onclick="Element.show('entry_basic');Element.show('hide');
Element.hide('reveal');new Effect.Highlight('entry_basic');return
false;">Show basic information about the entry</a></h8>
<fieldset id="entry_basic">
<legend>Basic information <h8> <a href="#" id="hide" onclick="new
Effect.Fade('entry_basic');Element.show('reveal');return false;">-
Hide</a></h8></legend>
<%= hidden_field "entry", "id" %>
<ol>
  <li class="left">
    <label for="entry_title"><span
class="accesskey">T</span>itle:</label>
    <%= text_field "entry", "title", {:accesskey => "t", :onblur =>
"makeSlug();"} %>
  </li>
  <li class="right">
    <%= hidden_field 'entry', 'slug'%>
  </li>
  <li id="whatThis1" class="right">
  <p>'Tags' help people to find your article. They are words used to
describe the article and separated by a space. There is no need to add
tags, but it would help promote your article E.g. music kaiser cheifs
etc.   </p><h8> <a href="#" onclick="new
Effect.Fade('whatThis1');Element.show('whatThisLink');return
false;">Hide</a></h8>

  </li>

  <li class="left">
    <label for="entry_tags">T<span class="accesskey">a</span>gs: <h8><a
href="#" id="whatThisLink"
onclick="Element.show('whatThis1');Effect.Fade('whatThisLink');new
Effect.Highlight('whatThis1');return false;">What's
This?</a></h8></label>
    <%= text_field "entry", "tags", {:value => tags(@entry), :accesskey
=> "a",
     :autocomplete => "off", :onkeydown => "keyPress(event);", :onkeyup
=> "suggestTags(event);"} %>
  </li>
  <li class="right">
    <%= hidden_field 'entry', 'state', :value=> "D" %>
  </li>
  <li class="left" id="entry_suggest">
    <label>Suggestions:</label>
    <ul id="entry_suggest_suggestions"></ul>
  </li>
  <li id="hidden" class="right">
    <label for="entry_date_published">Date:</label>
    <%- if @entry -%>
    <%= datetime_select "entry", "date_published" %>
    <%- else -%>
    <%- t = Time.now + (Option["general_timedifference"].to_f * 60 * 60)
-%>
    <%= select_year(t, {:prefix => "entry", :field_name =>
"date_published(1i)"}) +
        select_month(t, {:prefix => "entry", :field_name =>
"date_published(2i)"}) +
        select_day(t, {:prefix => "entry", :field_name =>
"date_published(3i)"}) + " &mdash; " +
        select_hour(t, {:prefix => "entry", :field_name =>
"date_published(4i)"}) + ":" +
        select_minute(t, {:prefix => "entry", :field_name =>
"date_published(5i)"}) %>
    <%- end -%>
  </li>

   <% if session["user"].permission == "admin" %>
   <li class="left">
    <label for="entry_user_id">A<span
class="accesskey">u</span>thor:</label>
    <%= select "entry", "user_id", @authors, {}, {:accesskey => "u"} %>

   <% else %>
    <%= hidden_field 'entry', 'user_id', :value=> session["user"].id %>
    <% end %>
  </li>
    </li>
  <li class="right">
  <div id="create">
  <%= submit_tag "Create Article", :id =>
"entry_submit_saveandcontinue", :onclick => "submitButton(this);new
Effect.Fade('entry_basic');Element.show('loading');" %>
  </div>
  </li>
</ol>
</fieldset>
<div id="loading"><p>Loading...</p></div>
<div id="step2">
<div id="entry_typebased" class="tabs">
<ul id="entry_types" class="tablist">
<%- for type in @types -%>
  <li id="entry_type_<%= type.id %>">
    <a href="#type" onclick="loadType(<%= type.id %>);"><%=
type.name.capitalize %></a></li>
<%- end -%>

</ul>

<%= hidden_field "entry", "type_id" %>
<%= hidden_field "entry", "description" %>
<%= hidden_field "entry", "contents" %>

<%= observe_form "live-entry-form",
          :frequency => 1,
          :update => "live-preview",
          :complete =>"Element.show('live-preview')",
          :url => {:controller => "entries", :action=>"show"} %>

<div id="message" style="color:#990000;"></div>
<%- for type in @types -%>
<%= render :partial => "type_" + type.name %>
<%- end -%>

<script type="text/javascript">
if($("entry_type_id").value != "") {
    loadType($("entry_type_id").value);
} else {
    loadType(1);
}
</script>
</div>

<div id="entry_pluginbased" class="tabs">
<ul id="entry_plugins" class="tablist">
<%- for plugin in @plugins -%>
  <li id="entry_plugin_<%= plugin['key'] %>">
    <a href="#plugin" onclick="loadPlugin('<%= plugin['key'] %>');"><%=
plugin["name"] %></a></li>
<%- end -%>
</ul>

<%- for plugin in @plugins -%>
<%= render :partial => "plugin_" + plugin["key"] %>
<%- end -%>

<script type="text/javascript">
loadPlugin("<%= @plugins[0]['key'] %>");


document.getElementById("whatThis1").hide();
document.getElementById("loading").hide();


</script>
<% if @entry.nil?%>
<script type="text/javascript">
document.getElementById("step2").hide();
document.getElementById("reveal").hide();
</script>
<% else %>
<script type="text/javascript">
document.getElementById("hide").hide();
document.getElementById("entry_basic").hide();
document.getElementById("create").hide();
</script>
<% end %>
</div>

<div id="entry_submit" class="submit">
<%= hidden_field_tag "submit", "" %>
<% #if session["user"].permission == "writer" %>
<%= submit_tag "Send To Editor", :id => "entry_submit_send", :onclick =>
"submitButton(this);" if (@entry and @entry.state != "E") or ([email protected])
%>
<% #end %>
<% if session["user"].permission == "admin" %>
<%= submit_tag "Publish Live", :id => "entry_submit_publish", :onclick
=> "submitButton(this);" if (@entry and @entry.state != "P") or
([email protected]) %>
<% end %>
<%= submit_tag "Save and Preview", :id => "entry_submit_save", :class =>
"default", :onclick => "submitButton(this);" %>
<%= submit_tag "Save and continue editing", :id =>
"entry_submit_saveandcontinue", :onclick => "submitButton(this);" %>
<%= tag :input, {:type => "button", :name => "commit", :value =>
"Cancel", :id => "entry_submit_cancel", :onclick =>
"window.history.back();"} %>
</div>

<%= end_form_tag %>

<% if @entry.nil?%>
<% else %>
 <%= javascript_include_tag 'jquery.rte.js' %>
<script type="text/javascript">

jQuery('.rte-zone').rte('rte.css');

</script>
<% end %>

<div style="clear: both;" />
</div>
</div>

Thanks in advance,

James

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs