<commit_before>angular.module("omniControllers")
	.controller("CreateCrowdsaleController",["$scope", "PropertyManager", "$timeout", "Transaction", "ModalManager", "SATOSHI_UNIT",
		function CreateCrowdsaleController($scope, PropertyManager, $timeout, Transaction, ModalManager, SATOSHI_UNIT){
		  $scope.ecosystem = 2;
		  $scope.propertyType = 2;
		  $scope.tokenStep = $scope.tokenMin =  0.<PASSWORD>;
		  $scope.tokenMax = "92233720368.54775807";
		  $scope.categories=[];
		  $scope.subcategories=[];
		  $scope.availableTokens=[];
		  $scope.propertyCategory='';
		  
		  var mastercoin, testMastercoin, bitcoin;
		  $scope.setEcosystem = function(){
		    PropertyManager.listProperties($scope.ecosystem).then(function(result){
		    	result.data.properties.forEach(function(property){
		    		if(property.currencyId==0)
		    			bitcoin=property;
		    		else if(property.currencyId==1)
		    			mastercoin=property;
		    		else if(property.currencyId==2)
		    			testMastercoin=property;
		    	})
		      $scope.availableTokens = result.data.properties.sort(function(a, b) {
		          var currencyA = a.propertyName.toUpperCase();
		          var currencyB = b.propertyName.toUpperCase();
		          return (currencyA < currencyB) ? -1 : (currencyA > currencyB) ? 1 : 0;
		      });
		      $scope.selectedCurrency = $scope.ecosystem == 1 ? mastercoin : testMastercoin;
		    });
		    $scope.categories=[];
		    $scope.subcategories=[];
		    $scope.loadCategories();
		  };
		  
		  $scope.loadCategories=function(){
		    PropertyManager.loadCategories($scope.ecosystem).then(function(result){  
		      $scope.categories=result.data.categories.sort();
		    });
		  };

		  $scope.loadSubcategories=function(category){
		    $scope.propertySubcategory = '';
		    PropertyManager.loadSubcategories($scope.ecosystem, category).then(function(result){  
		      $scope.subcategories=result.data.subcategories.sort();
		    });
		  };
		  
		  $scope.formatCurrencyDisplay = function(currencyDesired){
		    return currencyDesired.propertyName + " (" + currencyDesired.currencyId + ")";
		  };
		  
		  // Initialize the form
		  $scope.setEcosystem();
		  
		  $scope.isDivisible=function(){
		    return $scope.propertyType == 2 || $scope.propertyType == 66 || $scope.propertyType == 130;
		  };

		  // Estimated early bird bonus calculation
		  $scope.$watch(function(){ return $scope.deadline ? $scope.deadline.getTime() + $scope.earlyBirdBonus : 0;}, function(value){
		    if(value > 0){
		      var utcNow = new Date((new Date()).getTime() + (new Date()).getTimezoneOffset() * 60000);
		      $scope.initialEarlyBirdBonus = (((($scope.deadline.getTime() / 1000) - (utcNow.getTime() /1000 + 1800)) /604800 ) * $scope.earlyBirdBonus).toFixed(2);
		      $scope.initialEarlyBirdBonus = $scope.initialEarlyBirdBonus > 0 ? $scope.initialEarlyBirdBonus : 0.00;
		    } else 
		      $scope.initialEarlyBirdBonus = 0
		  });
		  
		  $scope.typeChanged = function(){
		    $scope.tokenStep = $scope.tokenMin = $scope.isDivisible() ? 0.00000001 : 1;
		    $scope.tokenMax = $scope.isDivisible() ? "92233720368.54775807" : "9223372036854775807";
		  };
		  
		  // TRASANCTION GENERATION CONFIG 
		  $scope.confirm = function(){
		  	//TODO: VALIDATIONS
		  	var fee = $scope.minersFee;
			var crowdsaleCreation = new Transaction(51,$scope.selectedAddress,fee,{
		          transaction_version:0,
		          ecosystem:$scope.ecosystem,
		          property_type : $scope.propertyType, 
		          previous_property_id:$scope.previousPropertyId || 0, 
		          property_category:$scope.propertyCategory || '\0', 
		          property_subcategory:$scope.propertySubcategory || '\0', 
		          property_name:$scope.propertyName, 
		          property_url:$scope.propertyUrl || '\0', 
		          property_data:$scope.propertyData || '\0', 
		          number_properties:$scope.isDivisible() ? +new Big($scope.numberOfTokens).times(SATOSHI_UNIT).valueOf() : +$scope.numberOfTokens,
		          transaction_from: $scope.selectedAddress,
		          currency_identifier_desired:$scope.selectedCurrency.currencyId,
		          deadline:Date.UTC($scope.deadline.getFullYear(),$scope.deadline.getMonth(),$scope.deadline.getDate(), $scope.deadline.getHours(), $scope.deadline.getMinutes(), 0, 0) / 1000,
		          earlybird_bonus:$scope.earlyBirdBonus,
		          percentage_for_issuer:$scope.percentageForIssuer,
		          donate: $scope.account.getSetting("donate")
		        });


			$scope.modalManager.openConfirmationModal({
				dataTemplate: '/views/modals/partials/crowdsale.html',
				scope:{
					title:"ASSETS_CROWDSALE_MODALTITLE",
				    divisible : $scope.isDivisible(),
				    propertyName : $scope.propertyName,
				    propertyData : $scope.propertyData,
				    propertyCategory : $scope.propertyCategory,
				    propertySubcategory : $scope.propertySubcategory,
				    propertyUrl : $scope.propertyUrl,
				    currenciesDesired : $scope.currenciesDesired,
				    deadline : (new Date(Date.UTC($scope.deadline.getFullYear(),$scope.deadline.getMonth(),$scope.deadline.getDate(), $scope.deadline.getHours(), $scope.deadline.getMinutes(), 0, 0))).toUTCString(),
				    earlyBirdBonus : $scope.initialEarlyBirdBonus,
				    percentageForIssuer : $scope.percentageForIssuer,
				    selectedAddress : $scope.selectedAddress,
				    fees : $scope.minerFees,
				    totalCost : crowdsaleCreation.totalCost,
					confirmText:"ASSETS_CROWDSALE_START"
				},
				transaction:crowdsaleCreation
			})
		  }
		  
		  // DATEPICKER CONFIGURATION
		  var nextMonth = new Date();
		  var offset = nextMonth.getTimezoneOffset() * 60000;
		  var minDeadline = new Date((new Date()).getTime() + 1800000 - offset);
		  $scope.today = function() {
		    $scope.deadline = minDeadline;
		  };
		  
		  nextMonth.setMonth(nextMonth.getMonth() +1);
		  $scope.deadline = new Date(nextMonth.getTime() + offset);

		  $scope.open = function($event) {
		    $event.preventDefault();
		    $event.stopPropagation();

		    $scope.opened = true;
		  };
		  
		  // Disable past dates
		  $scope.disabled = function(date, mode) {
		    return ( mode === 'day' && date.getTime() < (new Date()).getTime());
		  };
		  
		  $scope.dateOptions = {
		    formatYear: 'yy',
		    startingDay: 1,
		    minDate:minDeadline
		  };
		  
		  $scope.format = 'dd MMMM yyyy';
		  
		  $scope.$watch('deadline', function(value){
		    if (value < minDeadline) $scope.deadline = minDeadline;
		  });
		}])<commit_msg>Fix deadline generation and display<commit_after>angular.module("omniControllers")
	.controller("CreateCrowdsaleController",["$scope", "PropertyManager", "$timeout", "Transaction", "ModalManager", "SATOSHI_UNIT",
		function CreateCrowdsaleController($scope, PropertyManager, $timeout, Transaction, ModalManager, SATOSHI_UNIT){
		  $scope.ecosystem = 2;
		  $scope.propertyType = 2;
		  $scope.tokenStep = $scope.tokenMin =  0.0<PASSWORD>1;
		  $scope.tokenMax = "92233720368.54775807";
		  $scope.categories=[];
		  $scope.subcategories=[];
		  $scope.availableTokens=[];
		  $scope.propertyCategory='';
		  
		  var mastercoin, testMastercoin, bitcoin;
		  $scope.setEcosystem = function(){
		    PropertyManager.listProperties($scope.ecosystem).then(function(result){
		    	result.data.properties.forEach(function(property){
		    		if(property.currencyId==0)
		    			bitcoin=property;
		    		else if(property.currencyId==1)
		    			mastercoin=property;
		    		else if(property.currencyId==2)
		    			testMastercoin=property;
		    	})
		      $scope.availableTokens = result.data.properties.sort(function(a, b) {
		          var currencyA = a.propertyName.toUpperCase();
		          var currencyB = b.propertyName.toUpperCase();
		          return (currencyA < currencyB) ? -1 : (currencyA > currencyB) ? 1 : 0;
		      });
		      $scope.selectedCurrency = $scope.ecosystem == 1 ? mastercoin : testMastercoin;
		    });
		    $scope.categories=[];
		    $scope.subcategories=[];
		    $scope.loadCategories();
		  };
		  
		  $scope.loadCategories=function(){
		    PropertyManager.loadCategories($scope.ecosystem).then(function(result){  
		      $scope.categories=result.data.categories.sort();
		    });
		  };

		  $scope.loadSubcategories=function(category){
		    $scope.propertySubcategory = '';
		    PropertyManager.loadSubcategories($scope.ecosystem, category).then(function(result){  
		      $scope.subcategories=result.data.subcategories.sort();
		    });
		  };
		  
		  $scope.formatCurrencyDisplay = function(currencyDesired){
		    return currencyDesired.propertyName + " (" + currencyDesired.currencyId + ")";
		  };
		  
		  // Initialize the form
		  $scope.setEcosystem();
		  
		  $scope.isDivisible=function(){
		    return $scope.propertyType == 2 || $scope.propertyType == 66 || $scope.propertyType == 130;
		  };

		  // Estimated early bird bonus calculation
		  $scope.$watch(function(){ return $scope.deadline ? $scope.deadline.getTime() + $scope.earlyBirdBonus : 0;}, function(value){
		    if(value > 0){
		      var utcNow = new Date((new Date()).getTime() + (new Date()).getTimezoneOffset() * 60000);
		      $scope.initialEarlyBirdBonus = (((($scope.deadline.getTime() / 1000) - (utcNow.getTime() /1000 + 1800)) /604800 ) * $scope.earlyBirdBonus).toFixed(2);
		      $scope.initialEarlyBirdBonus = $scope.initialEarlyBirdBonus > 0 ? $scope.initialEarlyBirdBonus : 0.00;
		    } else 
		      $scope.initialEarlyBirdBonus = 0
		  });
		  
		  $scope.typeChanged = function(){
		    $scope.tokenStep = $scope.tokenMin = $scope.isDivisible() ? 0.00000001 : 1;
		    $scope.tokenMax = $scope.isDivisible() ? "92233720368.54775807" : "9223372036854775807";
		  };
		  
		  // TRASANCTION GENERATION CONFIG 
		  $scope.confirm = function(){
		  	//TODO: VALIDATIONS
		  	var fee = $scope.minersFee;
			var crowdsaleCreation = new Transaction(51,$scope.selectedAddress,fee,{
		          transaction_version:0,
		          ecosystem:$scope.ecosystem,
		          property_type : $scope.propertyType, 
		          previous_property_id:$scope.previousPropertyId || 0, 
		          property_category:$scope.propertyCategory || '\0', 
		          property_subcategory:$scope.propertySubcategory || '\0', 
		          property_name:$scope.propertyName, 
		          property_url:$scope.propertyUrl || '\0', 
		          property_data:$scope.propertyData || '\0', 
		          number_properties:$scope.isDivisible() ? +new Big($scope.numberOfTokens).times(SATOSHI_UNIT).valueOf() : +$scope.numberOfTokens,
		          transaction_from: $scope.selectedAddress,
		          currency_identifier_desired:$scope.selectedCurrency.currencyId,
		          deadline:Date.UTC($scope.deadline.getFullYear(),$scope.deadline.getMonth(),$scope.deadline.getDate(), $scope.deadline.getHours(), $scope.deadline.getMinutes(), 0, 0) / 1000,
		          earlybird_bonus:$scope.earlyBirdBonus,
		          percentage_for_issuer:$scope.percentageForIssuer,
		          donate: $scope.account.getSetting("donate")
		        });


			$scope.modalManager.openConfirmationModal({
				dataTemplate: '/views/modals/partials/crowdsale.html',
				scope:{
					title:"ASSETS_CROWDSALE_MODALTITLE",
				    divisible : $scope.isDivisible(),
				    propertyName : $scope.propertyName,
				    propertyData : $scope.propertyData,
				    propertyCategory : $scope.propertyCategory,
				    propertySubcategory : $scope.propertySubcategory,
				    propertyUrl : $scope.propertyUrl,
				    currenciesDesired : $scope.currenciesDesired,
				    deadline : (new Date(Date.UTC($scope.deadline.getFullYear(),$scope.deadline.getMonth(),$scope.deadline.getDate(), $scope.deadline.getHours(), $scope.deadline.getMinutes(), 0, 0))).toUTCString(),
				    earlyBirdBonus : $scope.initialEarlyBirdBonus,
				    percentageForIssuer : $scope.percentageForIssuer,
				    selectedAddress : $scope.selectedAddress,
				    fees : $scope.minerFees,
				    totalCost : crowdsaleCreation.totalCost,
					confirmText:"ASSETS_CROWDSALE_START"
				},
				transaction:crowdsaleCreation
			})
		  }
		  
		  // DATEPICKER CONFIGURATION
		  var deadline = new Date();
		  var offset = deadline.getTimezoneOffset() * 60000;
		  // set mn deadline to be half an hour ahead
		  var minDeadline = new Date(deadline.getTime() + 1800000 - offset);
		  $scope.today = function() {
		    $scope.deadline = minDeadline;
		  };
		  
		  deadline.setMonth(deadline.getMonth() +1);
		  $scope.deadline = new Date(deadline.getTime() - offset);

		  $scope.open = function($event) {
		    $event.preventDefault();
		    $event.stopPropagation();

		    $scope.opened = true;
		  };
		  
		  // Disable past dates
		  $scope.disabled = function(date, mode) {
		    return ( mode === 'day' && date.getTime() < (new Date()).getTime());
		  };
		  
		  $scope.dateOptions = {
		    formatYear: 'yy',
		    startingDay: 1,
		    minDate:minDeadline
		  };
		  
		  $scope.format = 'dd MMMM yyyy';
		  
		  $scope.$watch('deadline', function(value){
		    if (value < minDeadline) $scope.deadline = minDeadline;
		  });
		}])
{'fraction_non_alphanumeric': 0.13878922055118711, 'fraction_numerical': 0.022139094587373082, 'mean_word_length': 3.141637685741385, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6983369', 'n_tokens_mistral': 4877, 'n_tokens_neox': 3963, 'n_words': 588}