
var templSectH2;var proct;$("document").ready(function(){$('#btnSave').click(function(){$(this).slideUp();$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({mmsession:_mmsession,mm:_procmm}),url:_reposRoot+'/ProcessDefinition.asmx/SaveProcessTypeMetamodelDiagram',success:function(data){location.href=_reposRoot+'/library/ProcessTypes';}});});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);$('.ddlProcessType').val(-1);},"OK":function(){var linktypeid=$('.ddlProcessType').val();var linktypename=$('.ddlProcessType :selected').text();if(linktypeid==-1){linktypeid=null;linktypename=null;}
var newItem={sectionName:$.trim($("#sectionName").val()),tutorialText:$.trim($("#tutorialText").val()),direction:$("input[name='dir']:checked").val(),multiplicity:$("input[name='multip']:checked").val(),linktypename:linktypename,linktypeid:linktypeid};if(templSectH2==null)
{var temp=$('<div>'+proct.ProcessTypeTemplate+'</div>');templSectH2=$('<h2><span></span></h2>').appendTo(temp);}
templSectH2.attr('data-direction',newItem.direction);templSectH2.attr('data-multiplicity',newItem.multiplicity);templSectH2.attr('data-linktypeid',newItem.linktypeid);templSectH2.attr('data-linktypename',newItem.linktypename);if($('span',templSectH2).length==0){templSectH2.text(newItem.sectionName);}
else{$('span',templSectH2).text(newItem.sectionName);}
var elesUntilH2=$(templSectH2).nextUntil('h2');var bq=elesUntilH2.first('blockquote');if(bq.length==0)
{if(newItem.tutorialText.length>0)
{$('<blockquote></blockquote>').insertAfter(templSectH2).text(newItem.tutorialText);}}
else
{bq.text(newItem.tutorialText);}
proct.ProcessTypeTemplate=templSectH2.parents().last().html();$(this).dialog("close");$("#sectionName, #tutorialText").val("");$('input[name="dir"]').prop('checked',false);$('input[name="multip"]').prop('checked',false);$('.ddlProcessType').val(-1);$('#mapprocmm').html('');$('#imgprocmm').fadeOut('fast');$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({mmsession:_mmsession,mm:_procmm}),url:_reposRoot+'/ProcessDefinition.asmx/GetProcessTypeMetamodelDiagram',success:function(data){$('#imgprocmm').attr('src',_imageRoot+data.d.Image+"?t="+cBypass()).fadeIn('fast');$('#mapprocmm').html($(data.d.RegionMap).html());}});}}});$('#mapprocmm area').live('click',function(){var thisarea=$(this);var ptypeid=thisarea.data('ptypeid');var heading=thisarea.data('heading');proct=null;for(var i=0;i<_procmm.length;i++)
{if(_procmm[i].ProcessTypeId==ptypeid)
{proct=_procmm[i];break;}}
if((heading==null)||(heading.length==0))
{templSectH2=null;dlgSection.dialog('open');}
else
{var templ=$('<div>'+proct.ProcessTypeTemplate+'</div>');templSectH2=$('h2',templ).filter(function(){console.log($(this).text());return $.trim($(this).text())===$.trim(heading);});$('#sectionName').val($(templSectH2).text().trim());var h2=templSectH2;$("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);var elesUntilH2=$(h2).nextUntil('h2');$('#tutorialText').val(elesUntilH2.first('blockquote').text());dlgSection.dialog('open');}
return false;});});