
<div id="tags">
  <%#begin
	 1 代表是user类型
	 2 代表是project类型
	 3 代表是issue类型
	 4 代表是bid类型
	 5 代表是forum类型
	 6 代表是Attachment类型
	 7 代表是contest类型
	 8 代表是OpenSourceProject类型
	 9 代表是RelativeMemo类型
	#end%>
  <!--  3 代表的是issue 当是issue是 处理方式与前2个对象不同 -->
  <% if object_flag == '3' %>
      <span><%= image_tag("/images/sidebar/tags.png") %></span>
      <span class="font_title_tag"><%= l(:label_tag) %>:</span>
      <% if User.current.logged? %>
          <span> <%= toggle_link (image_tag "/images/sidebar/add.png"), 'put-tag-form-issue', {:focus => 'name-issue'} %></span>
      <% end %>

      <div id="tags_show_issue">
        <%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
      </div>
      <div id="put-tag-form-issue" style="display: none">
        <%= form_for "tag_for_save",:remote=>true,:url=>tag_path,
                     :update => "tags_show",
                     :complete => '$("#put-tag-form-issue").hide();' do |f| %>
            <%= f.text_field :name ,:id => "name-issue",:size=>"30",:require=>true,:maxlength => Setting.tags_max_length,:minlength=>1 %>
            <%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%>
            <%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%>
            <%= f.submit l(:button_project_tags_add),:class => "small"%>
            <%= link_to_function l(:button_cancel), '$("#put-tag-form-issue").hide();'%>
        <% end %>
      </div>

  <% elsif object_flag == '6' %>
      <span><%#= image_tag("/images/sidebar/tags.png") %></span>
		<span>
			<%= link_to (image_tag "/images/sidebar/add.png"), 'javascript:void(0);', :class => "tags_icona", :onclick=>"$('#put-tag-form-#{obj.class}-#{obj.id}').toggle(); readmore(this);" if User.current.logged? %>
          <%#= toggle_link (image_tag "/images/sidebar/add.png"), "put-tag-form-#{obj.class}-#{obj.id}", {:focus => "put-tag-form-#{obj.class}-#{obj.id} #name"} if User.current.logged? %>
		</span>
      &nbsp;&nbsp;

      <div id="tags_show">
      <div id="tags_show-<%=obj.class%>-<%=obj.id%>" style="display:inline; ">
        <%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
      </div>
      <div id="put-tag-form-<%=obj.class%>-<%=obj.id%>" style="display: none">
        <%= text_field "tag_name" ,"name"%>
        <input id="object_id" type="text" size="20" name="object_id" value='<%=obj.id%>' class="hidden">
        <input id="object_flag" type="text" size="20" name="object_flag" value='<%=object_flag%>' class="hidden">
        <%= submit_tag l(:button_add), :name=>"add_tag",:remote=>"false", :format => 'js' %>
         <div class='hidden'>
              <% preTags = @preTags.nil? ? [] : @preTags %>
              <% preTags.each do |tag|%>
                  <%= link_to tag, "
					javascript:(function(){
						var $tagInputVal = $('#put-tag-form-"+obj.class.to_s+"-"+obj.id.to_s+"').find('#name');
						var tagArr = [];
						tagArr = tagArr.concat( $tagInputVal[0].value.split(',') );
						tagArr = tagArr.concat('"+tag.to_s+"');
						tagArr = cleanArray(tagArr);
						$tagInputVal.val(tagArr.join(','));
					})();
					"
                  %>
              <% end%>
            </div>
            <%#= link_to_function l(:button_cancel), "$(\"#put-tag-form-#{obj.class}-#{obj.id}\").hide();"%>
       </div>
      </div>
  <% else %>

      <span><%= image_tag("/images/sidebar/tags.png") %></span>
      <span class="font_title_tag"><%= l(:label_tag) %>:</span>

      <% if User.current.logged? %>
          <span><%= toggle_link (image_tag "/images/sidebar/add.png"), 'put-tag-form', {:focus => 'name'} %></span>
      <% end %>

      <div id="tags_show">
        <%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
      </div>
      <div id="put-tag-form" style="display: none">

        <%= form_for "tag_for_save",:remote=>true,:url=>tag_path,
                     :update => "tags_show",
                     :complete => '$("#put-tag-form").hide();' do |f| %>
            <%= f.text_field :name ,:id => "name",:size=>"28",:require=>true,:maxlength => Setting.tags_max_length,:minlength=>Setting.tags_min_length %>
            <%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%>
            <%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%>
            <%= f.submit l(:button_project_tags_add),:class => "small" %>
            <%= link_to_function l(:button_cancel), '$("#put-tag-form").hide();'%>
        <% end %>
      </div>
  <% end %>
</div>


<script language="JavaScript">
    function submitForm123(objId,objTag){
        alert("OK");
        $.ajax({
            type :"Get",
            url :'<%= users_tag_saveEx_path%>',
            remote:"true",
            format:"js",
            data: {
                tagname: $('tag_name_name').val(),
                obj_id: encodeURIComponent(objId),
                obj_flag:encodeURIComponent(objTag)
            },
            success: function(data, textStatus){
                alert("OK");
                $(id).empty();
                $(id).html('123');
                $("#" +  id + " #name").val("");
            }
        })

    }
    function eval_ajax (xhr, textStatus) {
        if (textStatus == 'success') {
            eval(xhr.responseText);
        } else if (textStatus == 'error') {
            alert('error');
        }
    }

</script>

<script type='text/javascript'>
    function tagAddClick(id,objId,objTag)
    {
        alert("OK");
        $.ajax({
            type :"POST",
            url :'<%= users_tag_saveEx_path%>',
            data: {
                tagname: $('tag_name_name').val(),
                obj_id: encodeURIComponent(objId),
                obj_flag:encodeURIComponent(objTag)
            },
            success: function(data, textStatus){
                alert("OK");
                $(id).empty();
                $(id).html('123');
                $("#" +  id + " #name").val("");
            }
        })
    }
</script>
