(function(NS){var $0='model.js';NS.FragmentModel=function($1)
{if(!u.isNumber($1)||$1<0)
throw new Error('The fragment id is invalid.');var $2=new Date();u.initClassInstance(this,{data:{id:parseInt($1,10),type:'Markdown',title:'',content:'',option:{},view:{},ctime:$2,mtime:$2},html:''});var d=this.d;try
{u.importModule(this,u.RefCount);this.GetData=this.$3;this.RenderHTML=this.$4;u.info('[CREATE] FragmentModel '+d.data.id,$0);}
catch(ex)
{u.cleanupClassInstance(this,NS.FragmentModel);throw ex;}};var $5=NS.FragmentModel;$5.prototype={_Cleanup:function()
{var d=this.d;if(d)
{$5.$6.remove(parseInt(d.data.id,10));u.info('[DELETE] FragmentModel '+d.data.id,$0);}},$7:function($8)
{},$3:function()
{var d=this.d,$8=null;u.unthrow(function(){$8=NS.DB.FindFragment(d.data.id);});if($8)
{$8.id=d.data.id;$8.type=d.data.type;d.data=$8;}
this.GetData=this.$9;return this.GetData();},$9:function()
{return u.shallowCopy(this.d.data);},$4:function()
{var $8=this.GetData();this.d.html=$5.$a.makeHtml($8.content);this.RenderHTML=this.$b;return this.RenderHTML();},$b:function()
{return this.d.html;},GetID:function()
{return this.d.data.id;},SetData:function($8)
{var $c=this.d.data;$8=u.applyIf(u.shallowCopy($8),$c);$8.id=$c.id;$8.type=$c.type;$8.ctime=$c.ctime;$8.mtime=new Date();if(!$5.ValidateType($8.type))
throw new Error(String($8.type)+' is an invalid fragment type.');NS.DB.StoreFragment(this.d.data=$8);this.RenderHTML=this.$4;}};$5.$a=new Showdown.converter();$5.$6=new u.ObjectCache();$5.$d={'Markdown':true};$5.Create=function($8)
{var $2=new Date();var $8=u.applyIf(u.shallowCopy($8),{type:'Markdown',title:'',content:'',option:{},view:{},ctime:$2,mtime:$2});if(!$5.ValidateType($8.type))
throw new Error(String($8.type)+' is an invalid fragment type.');var $1=NS.DB.CreateFragment($8);return $5.$6.find($1,function(){return new $5($1);});};$5.Find=function($1)
{$1=parseInt($1,10);return $5.$6.find($1,function(){return new $5($1);});};$5.RemoveAll=function()
{$5.$6.forEach(function($e){u.cleanupClassInstance($e);},this);$5.$6.removeAll();};$5.ValidateType=function($f)
{return $5.$d[String($f)]?true:false;};NS.ResourceModel=function($1,$g)
{if(!$1)
throw new Error('The resource id is invalid.');var $2=new Date();u.initClassInstance(this,{data:{id:String($1),title:String($g),fragments:[],option:{},view:{},ctime:$2,mtime:$2}});var d=this.d;try
{u.importModule(this,u.RefCount);this.GetData=this.$3;u.info('[CREATE] ResourceModel '+d.data.id,$0);}
catch(ex)
{u.cleanupClassInstance(this,NS.ResourceModel);throw ex;}};var $h=NS.ResourceModel;$h.prototype={_Cleanup:function()
{var d=this.d;if(d)
{$h.$6.remove(d.data.id);u.info('[DELETE] ResourceModel '+d.data.id,$0);}},$3:function()
{var d=this.d,$8=null;u.unthrow(function(){$8=NS.DB.FindResource(d.data.id);});if($8)
{$8.id=d.data.id;d.data=$8;}
this.GetData=this.$9;return this.GetData();},$9:function()
{var $8=u.shallowCopy(this.d.data);$8.fragments=u.shallowCopy($8.fragments);return $8;},SetData:function($8)
{var d=this.d;var $c=d.data;$8=u.applyIf(u.shallowCopy($8),$c);$8.id=$c.id;$8.ctime=$c.ctime;$8.mtime=new Date();NS.DB.StoreResource(d.data=$8);},Delete:function()
{NS.DB.DeleteResource(this.d.data.id);}};$h.$6=new u.ObjectCache();$h.Find=function($1,$g)
{return $h.$6.find($1,function(){return new $h($1,$g);});};$h.RemoveAll=function()
{$h.$6.forEach(function($i){u.cleanupClassInstance($i);},this);$h.$6.removeAll();};})(Infosketch);