
var selectedProcessType;$(document).ready(function(){createUploader();refreshTypeIcons();var stop=false;var editingSection=null;var editingAdditional="";var dlgSection=$("#sectionDialog").dialog({modal:true,autoOpen:false,width:'550px',buttons:{"Cancel":function(){$(this).dialog("close");$("#sectionName, #tutorialText").val("");$('input[name="dir"]').prop('checked',false);$('input[name="multip"]').prop('checked',false);},"OK":function(){var linktypeid=$('.ddlProcessType').val();var linktypename=$('.ddlProcessType :selected').text();if(linktypeid==-1)
{linktypeid=null;linktypename=null;}
var newItem=[{sectionName:$("#sectionName").val(),tutorialText:$("#tutorialText").val(),direction:$("input[name='dir']:checked").val(),multiplicity:$("input[name='multip']:checked").val(),sectionContent:editingAdditional,linktypename:linktypename,linktypeid:linktypeid}];var templatedSect=$("#sectionTemplate").tmpl(newItem);addHeadingDataClasses($('h2.dd_head',templatedSect));if(editingSection==null)
editingSection=templatedSect.appendTo(".templateBody");else
editingSection.replaceWith(templatedSect);$('.templateBody').refreshAccordion();$(this).dialog("close");$("#sectionName, #tutorialText").val("");$('input[name="dir"]').prop('checked',false);$('input[name="multip"]').prop('checked',false);}}});$('.templateBody h2').contents().wrap("<a href='#'></a>");$('.templateBody h2').each(function(){var elesUntilH2=$(this).nextUntil('h2');if($(elesUntilH2).length>0)
$(elesUntilH2).wrapAll("<div class='section'><div class='content'></div></div>");else
$(this).after("<div class='section'><div class='content'><p></p></div></div>");addHeadingDataClasses($(this));});$('.templateBody .section').prepend("<span class='editBar'><span title='Edit section' class='edit blueIcon ui-icon ui-icon-pencil'></span><span title='Delete section' class='delete blueIcon ui-icon ui-icon-close'></span></span>");$('.templateBody h2').each(function(){$(this).nextUntil('h2').andSelf().wrapAll("<div></div>");});$(".templateBody").accordion({header:"> div > h2",active:false,collapsible:true,autoHeight:false}).sortable({axis:"y",handle:"h2"});$("#addSection").click(function(event){editingSection=null;editingAdditional="";dlgSection.dialog('open');});$(".templateBody div .section .editBar .edit").live('click',function(){editingSection=$(this).closest(':data(sortable-item)');$('#sectionName').val(editingSection.find('h2 > a').text().trim());$('#tutorialText').val(editingSection.find('div.section > div.content > blockquote').text());var h2=editingSection.find('h2');$("input[name='dir']").filter('[value=\''+$(h2).attr('data-direction')+'\']').attr('checked','checked');$("input[name='multip']").filter('[value=\''+$(h2).attr('data-multiplicity')+'\']').attr('checked','checked');var linkedTypeId=$(h2).attr('data-linktypeid');if(linkedTypeId)
$('.ddlProcessType').val(linkedTypeId);else
$('.ddlProcessType').val(-1);editingAdditional=editingSection.find('div.section > div.content > *:not(blockquote)').outerHTML();dlgSection.dialog('open');});$(".templateBody div .section .editBar .delete").live('click',function(){var parent=$(this).closest(':data(sortable-item)');var head=parent.prev('h2');parent.fadeOut('slow',function(){$(this).remove();});$('templateBody').refreshAccordion();});});$.fn.refreshAccordion=function(){var activeIdx=$(this).accordion('option','active');return this.accordion('destroy').accordion({header:"> div > h2",active:activeIdx,collapsible:true,autoHeight:false}).sortable({axis:"y",handle:"h2"});};function createUploader(){var uploader=new qq.FileUploader({element:document.getElementById('iconUpload'),action:_reposRoot+'/upload/typeicon-'+typeId,allowedExtensions:['jpg','jpeg','png','gif'],debug:false,multiple:false,onComplete:function(id,fileName,responseJSON){if(responseJSON.success){refreshTypeIcons();$('.qq-upload-list').html('');}}});}
function refreshTypeIcons(){$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{typeId:"+typeId+"}",url:_reposRoot+'/ProcessDefinition.asmx/GetProcessTypeIcons',success:function(data){onGotIcons(data);}});};function onGotIcons(data){$('#typeIcon').html('').append(data.d);}
function saveTemplate(isSaving){if(isSaving)
$('.btnSave a').text('Saving...');else
$('.btnEdit a').text('Please wait...');if($('.templateBody').is(":visible")){var editor=tinyMCE.get('ctl00_ctl00_ContentBody_ContentMain_htmlType_htmlType_ed');var templateHtml=editor.getContent();$('.templateBody > div').each(function(){var h2=$(this).find('h2');var cleanH2=$('<h2 class="dd_head"><span>'+$(this).find('h2 > a').text().trim()+'</span></h2>');$(cleanH2).attr('data-direction',$(h2).attr('data-direction'));$(cleanH2).attr('data-multiplicity',$(h2).attr('data-multiplicity'));$(cleanH2).attr('data-linktypeid',$(h2).attr('data-linktypeid'));$(cleanH2).attr('data-linktypename',$(h2).attr('data-linktypename'));templateHtml+=$(cleanH2).outerHTML();templateHtml+=$(this).find('div.section > div.content').html();});editor.setContent(templateHtml);}}
function addHeadingDataClasses(cleanH2){var hdd=cleanH2.attr('data-direction');if(hdd==undefined){hdd='';}
var hdm=cleanH2.attr('data-multiplicity');if(hdm==undefined){hdm='';}
cleanH2.removeClass('hdd_in');cleanH2.removeClass('hdd_out');cleanH2.removeClass('hdd_inout');cleanH2.removeClass('hdm_0__1');cleanH2.removeClass('hdm_0__n');cleanH2.removeClass('hdm_1__1');cleanH2.removeClass('hdm_1__n');cleanH2.addClass('hdd_'+hdd.replace(/\W/g,'_'));cleanH2.addClass('hdm_'+hdm.replace(/\W/g,'_'));}
jQuery.fn.outerHTML=function(){return $('<div></div>').append(this.clone()).html();}