angular.module("RdmApp").controller("timelineCtrl",["$scope","$rootScope","common","DTOptionsBuilder","DTColumnBuilder","$http","$q","ApiServer","nowTime",function(e,t,a,n,i,l,s,o,u){t.dataTimeline=[],void 0!==t.datakelas[t.selectKelas]?void 0!==t.datakelas[t.selectKelas].timeline?t.dataTimeline=t.datakelas[t.selectKelas].timeline:t.datakelas[t.selectKelas].timeline=[]:(t.datakelas[t.selectKelas]=[],t.datakelas[t.selectKelas].timeline=[]),e.nowTime=u,e.row=0,e.rowperpage=3,e.newPost={},e.newKomen={},e.newPost.image="",e.newPost.link="",e.newPost.text="",e.newPost.type=3,e.busy=!1,e.loading=!1,e.setType=function(t){e.newPost.type=t},e.saveComent=function(t,a){$.blockUI({}),e.newKomen={},e.newKomen.forumrespon_komentar=a,e.newKomen.forum_id=t.forum_id,o.post("guru/timeline/savekomen",e.newKomen,(function(a){$.unblockUI({}),a.success?(e.updatePosts(t),e.newPost.image="",e.newPost.link="",e.newPost.text="",e.newPost.type=3,Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Disimpan",timer:1e3})):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:a.message})}))},e.browseimage=function(){$("#imageFile").click()},e.removeImage=function(){e.newPost.image=""},e.sendPost=function(){$.blockUI({}),o.post("guru/timeline/save",e.newPost,(function(t){$.unblockUI({}),t.success?(e.getnewPosts(),e.newPost.image="",e.newPost.link="",e.newPost.text="",e.newPost.type=1,Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Disimpan",timer:1e3})):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:t.message})}))},e.getnewPosts=function(){t.dataTimeline.length>0&&(forum_id=t.dataTimeline[0].forum_id),o.get("guru/timeline/newdata/"+forum_id,(function(a){a.success&&(e.row+=e.rowperpage,e.$apply((function(){angular.forEach(a.data,(function(e){t.dataTimeline.unshift(e)})),null==t.datakelas[t.selectKelas]&&(t.datakelas[t.selectKelas]=[]),null==t.datakelas[t.selectKelas].timeline&&(t.datakelas[t.selectKelas].timeline=[]),t.datakelas[t.selectKelas].timeline=t.dataTimeline,setTimeout((function(){$(".lazy").Lazy()}),1e3)})))}))},e.updatePosts=function(e){$.blockUI({}),forum_id=e.forum_id,o.get("guru/timeline/getupdatedata/"+forum_id,(function(a){if($.unblockUI({}),a.success){e=a.data;const n=t.dataTimeline.findIndex((e=>e.forum_id===a.data.forum_id));t.dataTimeline[n]=a.data,null==t.datakelas[t.selectKelas]&&(t.datakelas[t.selectKelas]=[]),null==t.datakelas[t.selectKelas].timeline&&(t.datakelas[t.selectKelas].timeline=[]),t.datakelas[t.selectKelas].timeline=t.dataTimeline}}))},e.getPosts=function(){e.busy||(e.loading=!0,e.busy=!0,forum_id="0",t.dataTimeline.length>0&&(forum_id=t.dataTimeline[t.dataTimeline.length-1].forum_id),o.get("guru/timeline/data/"+forum_id,(function(a){a.success?a.data.length>0?(e.row+=e.rowperpage,e.$apply((function(){angular.forEach(a.data,(function(e){t.dataTimeline.push(e)})),null==t.datakelas[t.selectKelas]&&(t.datakelas[t.selectKelas]=[]),null==t.datakelas[t.selectKelas].timeline&&(t.datakelas[t.selectKelas].timeline=[]),t.datakelas[t.selectKelas].timeline=t.dataTimeline,e.busy=!1,e.loading=!1,setTimeout((function(){$(".lazy").Lazy()}),1e3)}))):(e.busy=!0,e.loading=!1):(e.busy=!1,e.loading=!1)})))},e.$on("pictureInsert",(function(t,a){e.newPost.image=a})),0==t.dataTimeline.length&&e.getPosts(),$("#postText").focus()}]),angular.module("RdmApp").directive("myDirective",["httpPostFactory",function(e){return{restrict:"A",scope:!0,link:function(t,a,n){a.bind("change",(function(){$.blockUI({});var n=new FormData;n.append("file",a[0].files[0]);var i=a[0].getAttribute("data-url");a[0].getAttribute("image-container");e(i,n,(function(e){$.unblockUI({}),e&&e.success?t.$emit("pictureInsert",e.data):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:e.data})}))}))}}}]);