directive.js 2.5 KB
"use strict";
var DirectiveModule = angular.module('DirectiveModule',[
	'homeDirective'
]);


DirectiveModule.directive('keditorEdit',[
	'$rootScope',
	'$location',
	'BaseService',
	function ($rootScope, $location, BaseService) {
		return {
			restrict:'EA',
			link:function(scope, el, attr) {
				// KindEditor.ready(function(K) {
				window.editor = KindEditor.create('#prodcut-keditor-edit',{
					uploadJson : '../fileupload/kindUpload',
					fileManagerJson : '../fileupload/kindUpload',
					allowFileManager : true
				});
				// });
				scope.$watch('details',function(value){
					
					window.editor.html(value)
				})
			}
		}
	}
]);

DirectiveModule.directive('tree', [
      '$rootScope',
      'SysResourceService',                            
      function($rootScope, SysResourceService) {
		  return {
			    require: '?ngModel',
			    restrict: 'A',
			    link: function (scope, element, attrs, ngModel) {
			      //var opts = angular.extend({}, $scope.$eval(attrs.nlUploadify));
			      var setting = {
		    		check: {
		  				enable: true
		  			},
		  			data: {
		  				key : {
		  					checked : 'checked'
		  				},
		  				simpleData: {
		  					enable: true,
		  					idKey: "id",
		  					pIdKey: "parentId",
		  					rootPId: 0
		  				}
		  			},
			        callback: {
			        	onCheck: function (event, treeId, treeNode, clickFlag) {
			        		console.log(treeNode);
			        	},
			        	onClick:function(event, treeId, treeNode, clickFlag) {
			        		scope.resource={
			        				id:treeNode.id,
			         				name:treeNode.name,
			         				type:treeNode.type,
			         				parentId:treeNode.parentId,
			         				resourceUrl:treeNode.resourceUrl,
			         				target:treeNode.target,
			         				iconImg:treeNode.iconImg,
			         				sort:treeNode.sort,
			        	 			isShow:1
			         		};
			        		$rootScope.$apply();
			        	}
			        }
			      };
			      scope.ztrees = [];
			      SysResourceService.getTreeSysResource(function (res) {
			    	  if(res.code == 0) {
			    		  scope.ztrees = res.data;
			    		  $.fn.zTree.init(element, setting, scope.ztrees);
			    	  }
			      });
			    }
		  };
	}
]);

DirectiveModule.directive('onClickMenu', function ($timeout) {
    return {
        restrict: 'A',
        link: function(scope, element, attr) {
        	if (scope.$last === true) {
                $timeout(function() {
                    scope.$emit('ngRepeatFinished');
                });
            }
        }
    };
});