text: /********************************************************************************
   * generated by de.acegen
   ********************************************************************************/
  
  
  
  
  import AsynchronousCommand from "../../ace/AsynchronousCommand";
  import Event from "../../ace/Event";
  import * as AppUtils from "../../../src/AppUtils";
  import * as AppState from "../../../src/AppState";
  import LoadCardsAction from "../../../src/card/actions/LoadCardsAction";
  import ReloadCategoryTreeAction from "../../../src/category/actions/ReloadCategoryTreeAction";
  
  export default class AbstractScheduleSelectedCardsCommand extends AsynchronousCommand {
      constructor() {
          super("card.ScheduleSelectedCardsCommand");
      }
      
      initCommandData(data) {
          data.cardIds = AppState.get(
          	["rootContainer", "mainView", "authorView", "categoryTree", "cardView", "selectedCardIds"]
          )
          ;
          data.boxId = AppState.get(
          	["rootContainer", "mainView", "authorView", "boxId"]
          )
          ;
          data.filterNonScheduled = AppState.get(
          	["rootContainer", "mainView", "authorView", "categoryTree", "filter", "filterNonScheduled", "value"]
          )
          ;
          data.outcomes = [];
      }
  
  	addNoFilterOutcome(data) {
  		data.outcomes.push("noFilter");
  	}
  	addFilterOutcome(data) {
  		data.outcomes.push("filter");
  	}
  
  	execute(data) {
  	    return new Promise((resolve, reject) => {
  	    	let payload = {
  	    		cardIds : data.cardIds,
  	    		boxId : data.boxId
  	    	};
  			AppUtils.httpPost(
  					`${AppUtils.settings.rootPath}/cards/schedule`, 
  					data.uuid, 
  					true,
  					 payload)
  				.then(() => {
  					this.handleResponse(data, resolve, reject);
  				}, (error) => {
  					data.error = error;
  					this.handleError(data, resolve, reject);
  				})
  				.catch(x => reject(x));
  	    });
  	}
  	
  	publishEvents(data) {
  		return new Promise((resolve) => {
  			const events = [];
  			const actionsToBeTriggered = [];
  			if (data.outcomes.includes("noFilter")) {
  				events.push(new Event('card.ScheduleSelectedCardsNoFilterEvent'));
  				actionsToBeTriggered.push(
  					{
  						action: new LoadCardsAction(), 
  						data: {
  						}
  					}
  				);
  			}
  			if (data.outcomes.includes("filter")) {
  				events.push(new Event('card.ScheduleSelectedCardsFilterEvent'));
  				actionsToBeTriggered.push(
  					{
  						action: new ReloadCategoryTreeAction(), 
  						data: {
  							selectedCategoryId: data.selectedCategoryId, 
  							categoryIdToBeExpanded: data.categoryIdToBeExpanded
  						}
  					}
  				);
  			}
  			
  			this.publish(events, data).then(() => {
  		  		AppState.stateUpdated();
  				this.trigger(actionsToBeTriggered).then(resolve);
  			});
  		})
  	
  	}
  
  }
  
  
  
  /******* S.D.G. *******/
  
  
  
  