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