<commit_before>define(['app','angular-form-controls'], function (app) {

    app.directive('workflowStdButtons',["$q", "$timeout", function($q, $timeout){

    	return{
    		restrict: 'EAC',
    		replace:false,
    		templateUrl: '/app/views/directives/workflow-std-buttons.html',
    		scope: {
    			getDocumentFn : '&document'
    		},
            link: function ($scope, $element)
			{
				$scope.errors              = null;
                var next_fs
                $("#progressbar li button").click(function(){
                	next_fs = $(this).parent();
                    next_fs.nextAll().removeClass("active");
                    next_fs.prevAll().addClass("active");
                    next_fs.addClass("active");

                });

                //BOOTSTRAP Dialog handling
				var qCancelDialog = $element.find("#dialogCancel");

				$scope.cancelDialogDefered = [];

				$scope.showCancelDialog = function(visible) {
        			  if($('form').filter('.dirty').length == 0) {
        				 $scope.$emit("documentClosed");
        				 return;
        			  }

					var isVisible = qCancelDialog.css("display")!='none';

					if(visible == isVisible)
						return $q.when(isVisible);

					var defered = $q.defer();

					$scope.cancelDialogDefered.push(defered)

					qCancelDialog.modal(visible ? "show" : "hide");

					return defered.promise;
				}


				qCancelDialog.on('shown.bs.modal' ,function() {

					$timeout(function(){

						var promise = null;
						while((promise=$scope.cancelDialogDefered.pop()))
							promise.resolve(true);
					});
				});

				qCancelDialog.on('hidden.bs.modal' ,function() {

					$timeout(function(){

						var promise = null;
						while((promise=$scope.cancelDialogDefered.pop()))
							promise.resolve(false);
					});
				});

                $scope.loadSecurity();
			},
    		controller: ["$rootScope","$scope", "IStorage", "editFormUtility", "$route","IWorkflows",
            function ($rootScope, $scope, storage, editFormUtility, $route, IWorkflows)
			{

                $scope.loadSecurity = function(){
                    $timeout(function(){$scope.updateSecurity();}, 3500);
                }
				//====================
				//
				//====================
				$scope.updateSecurity = function()
				{
                    if(!$scope.getDocumentFn().header || !$scope.getDocumentFn().header.languages)
                        $scope.loadSecurity();

                    $scope.languages = $scope.getDocumentFn().header.languages;
					$scope.security = {};
					$scope.loading = true;
					$q.when($scope.getDocumentFn()).then(function(document){


						if(!document || !document.header)
							return;

						var identifier = document.header.identifier;
						var schema     = document.header.schema;

						var a = storage.documents.exists(identifier).then(function(exist){

							var q = exist
								  ? storage.documents.security.canUpdate(document.header.identifier, schema)
								  : storage.documents.security.canCreate(document.header.identifier, schema);

							return q.then(function(allowed) {
								$scope.security.canSave = allowed
							});
						})

						var b = storage.drafts.exists(identifier).then(function(exist){

							var q = exist
								  ? storage.drafts.security.canUpdate(document.header.identifier, schema)
								  : storage.drafts.security.canCreate(document.header.identifier, schema);

							return q.then(function(allowed) {
								$scope.security.canSaveDraft = allowed
							});
						})

						return $q.all([a,b]);

					}).finally(function(){
<commit_msg>try fix for languages errror<commit_after>define(['app','angular-form-controls'], function (app) {

    app.directive('workflowStdButtons',["$q", "$timeout", function($q, $timeout){

    	return{
    		restrict: 'EAC',
    		replace:false,
    		templateUrl: '/app/views/directives/workflow-std-buttons.html',
    		scope: {
    			getDocumentFn : '&document'
    		},
            link: function ($scope, $element)
			{
				$scope.errors              = null;
                var next_fs
                $("#progressbar li button").click(function(){
                	next_fs = $(this).parent();
                    next_fs.nextAll().removeClass("active");
                    next_fs.prevAll().addClass("active");
                    next_fs.addClass("active");

                });

                //BOOTSTRAP Dialog handling
				var qCancelDialog = $element.find("#dialogCancel");

				$scope.cancelDialogDefered = [];

				$scope.showCancelDialog = function(visible) {
        			  if($('form').filter('.dirty').length == 0) {
        				 $scope.$emit("documentClosed");
        				 return;
        			  }

					var isVisible = qCancelDialog.css("display")!='none';

					if(visible == isVisible)
						return $q.when(isVisible);

					var defered = $q.defer();

					$scope.cancelDialogDefered.push(defered)

					qCancelDialog.modal(visible ? "show" : "hide");

					return defered.promise;
				}


				qCancelDialog.on('shown.bs.modal' ,function() {

					$timeout(function(){

						var promise = null;
						while((promise=$scope.cancelDialogDefered.pop()))
							promise.resolve(true);
					});
				});

				qCancelDialog.on('hidden.bs.modal' ,function() {

					$timeout(function(){

						var promise = null;
						while((promise=$scope.cancelDialogDefered.pop()))
							promise.resolve(false);
					});
				});

                $scope.loadSecurity();
			},
    		controller: ["$rootScope","$scope", "IStorage", "editFormUtility", "$route","IWorkflows",
            function ($rootScope, $scope, storage, editFormUtility, $route, IWorkflows)
			{

                $scope.loadSecurity = function(){
                    $timeout(function(){$scope.updateSecurity();}, 3500);
                }
				//====================
				//
				//====================
				$scope.updateSecurity = function()
				{
                    if(!$scope.getDocumentFn().header || !$scope.getDocumentFn().header.languages)
                        $scope.loadSecurity();
                
					$scope.security = {};
					$scope.loading = true;
					$q.when($scope.getDocumentFn()).then(function(document){

						if(!document || !document.header)
							return;

                        $scope.languages = document.header.languages;
						var identifier = document.header.identifier;
						var schema     = document.header.schema;

						var a = storage.documents.exists(identifier).then(function(exist){

							var q = exist
								  ? storage.documents.security.canUpdate(document.header.identifier, schema)
								  : storage.documents.security.canCreate(document.header.identifier, schema);

							return q.then(function(allowed) {
								$scope.security.canSave = allowed
							});
						})

						var b = storage.drafts.exists(identifier).then(function(exist){

							var q = exist
								  ? storage.drafts.security.canUpdate(document.header.identifier, schema)
								  : storage.drafts.security.canCreate(document.header.identifier, schema);

							return q.then(function(allowed) {
								$scope.security.canSaveDraft = allowed
							});
						})

						return $q.all([a,b]);

					}).finally(function(){

{'fraction_non_alphanumeric': 0.15935591338145474, 'fraction_numerical': 0.00138811771238201, 'mean_word_length': 2.238202247191011, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4377412', 'n_tokens_mistral': 2661, 'n_tokens_neox': 2007, 'n_words': 294}