ACMS.Dispatch.Edit._add=function($unit){if(0===$unit.$target.size())return false;var Edit=this;var url="";if(ACMS.Config.admin=="form2-edit")url=ACMS.Library.acmsLink({tpl:"ajax/form-unit-add-list.json"},true);else url=ACMS.Library.acmsLink({tpl:"ajax/unit-add-list.json"},true);$.getJSON(url,function(data){$.each(data.type,function(i){var type=this;var $input=$($.parseHTML('<input type="button" value="'+data.label[i]+'" class="btn" style="margin-right:5px;" />'));$unit.$target.find(".sorthandle").append($input);
$input.click(function(){var tpl="";if(ACMS.Config.admin=="form2-edit")tpl="ajax/form-unit-add-detail.html";else tpl="ajax/unit-add-detail.html";var url=ACMS.Library.acmsLink({tpl:tpl,admin:"entry-add-"+type,Query:{hash:Math.random().toString()}},true);$.get(url,function(html){var $item=$(ACMS.Config.Edit.itemMark,html);var size=$unit.find(':input[name="sort[]"]').last().find("option").size();var start=$unit.$target.nextAll(ACMS.Config.Edit.itemMark).size()?parseInt($unit.$target.nextAll(ACMS.Config.Edit.itemMark).first().find(':input[name="sort[]"]').val(),
10):size+1;$item.hide();$unit.$target.before($item);$item.fadeIn();$unit.find(ACMS.Config.Edit.itemMark).each(function(){var $select=$(':input[name="sort[]"]',this);var $option=$select.find("option");var max=parseInt($option.last().attr("value"),10);var limit=size+$item.size()-$option.size();for(var i=1;i<=limit;i++){var value=max+i;$select.append('<option value="'+value+'">'+value+"</option>")}});$item.each(function(i){$(':input[name="sort[]"]',this).val(start+i)});$unit.$target.nextAll(ACMS.Config.Edit.itemMark).each(function(){var $sort=
$(':input[name="sort[]"]',this);$sort.val(parseInt($sort.val(),10)+$item.size())});if($unit.$range.size()){var max=0;$unit.$range.find("option").each(function(){var value=parseInt($(this).val(),10);if(max<value)max=value});$unit.$range.find('option[value="'+max+'"]').after('<option value="'+(max+1)+'">'+(max+1)+"</option>")}Edit._refresh($unit);Edit.formUnitGroup($item);Edit.extendTagSelect($item);if($("img.column-map",$unit).size())ACMS.Library.googleLoadProxy("maps","3",{callback:function(){ACMS.Library.yahooLoadProxy({callback:function(){$item.each(function(){Edit._item(this,
$unit)})},error:function(){$item.each(function(){Edit._item(this,$unit)})}})},other_params:"sensor="+ACMS.Config.Gmap.sensor});else $item.each(function(){Edit._item(this,$unit)})})})})})};
