@@ -7,7 +7,6 @@ window['fabric'] = fabric.fabric;
77import ComponentController from '../componentController' ;
88import * as EventEmitter2 from 'eventemitter2' ;
99window [ 'EventEmitter2' ] = EventEmitter2 ;
10- import DrawingTool from '../../lib/drawingTool/drawing-tool' ;
1110import { DrawService } from './drawService' ;
1211
1312class DrawController extends ComponentController {
@@ -106,21 +105,10 @@ class DrawController extends ComponentController {
106105
107106 this . componentType = this . componentContent . type ;
108107
109- if ( this . isStudentMode ( ) || this . isAuthoringComponentPreviewMode ( ) ) {
110- this . isSaveButtonVisible = this . componentContent . showSaveButton ;
111- this . isSubmitButtonVisible = this . componentContent . showSubmitButton ;
112- this . isResetButtonVisible = true ;
113- this . drawingToolId = 'drawingtool_' + this . nodeId + '_' + this . componentId ;
114- } else if ( this . isGradingMode ( ) || this . isGradingRevisionMode ( ) ) {
115- const componentState = this . $scope . componentState ;
116- if ( componentState != null ) {
117- if ( this . isGradingRevisionMode ( ) ) {
118- this . drawingToolId = 'drawingtool_gradingRevision_' + componentState . id ;
119- } else {
120- this . drawingToolId = 'drawingtool_' + componentState . id ;
121- }
122- }
123- }
108+ this . isSaveButtonVisible = this . componentContent . showSaveButton ;
109+ this . isSubmitButtonVisible = this . componentContent . showSubmitButton ;
110+ this . isResetButtonVisible = true ;
111+ this . drawingToolId = 'drawingtool_' + this . nodeId + '_' + this . componentId ;
124112
125113 /*
126114 * Running this inside a timeout ensures that the code only runs after the markup is rendered.
@@ -193,67 +181,31 @@ class DrawController extends ComponentController {
193181 }
194182
195183 initializeDrawingTool ( ) {
196- this . drawingTool = new DrawingTool ( '#' + this . drawingToolId , {
197- stamps : this . componentContent . stamps || { } ,
198- parseSVG : true ,
199- width : this . width ,
200- height : this . height
201- } ) ;
202- let state = null ;
203- $ ( '#set-background' ) . on ( 'click' , ( ) => {
204- this . drawingTool . setBackgroundImage ( $ ( '#background-src' ) . val ( ) ) ;
205- } ) ;
206- $ ( '#resize-background' ) . on ( 'click' , ( ) => {
207- this . drawingTool . resizeBackgroundToCanvas ( ) ;
208- } ) ;
209- $ ( '#resize-canvas' ) . on ( 'click' , ( ) => {
210- this . drawingTool . resizeCanvasToBackground ( ) ;
211- } ) ;
212- $ ( '#shrink-background' ) . on ( 'click' , ( ) => {
213- this . drawingTool . shrinkBackgroundToCanvas ( ) ;
214- } ) ;
215- $ ( '#clear' ) . on ( 'click' , ( ) => {
216- this . drawingTool . clear ( true ) ;
217- } ) ;
218- $ ( '#save' ) . on ( 'click' , ( ) => {
219- state = this . drawingTool . save ( ) ;
220- $ ( '#load' ) . removeAttr ( 'disabled' ) ;
221- } ) ;
222- $ ( '#load' ) . on ( 'click' , ( ) => {
223- if ( state === null ) return ;
224- this . drawingTool . load ( state ) ;
225- } ) ;
226-
184+ this . drawingTool = this . DrawService . initializeDrawingTool (
185+ this . drawingToolId ,
186+ this . componentContent . stamps ,
187+ this . width ,
188+ this . height
189+ ) ;
227190 const componentState = this . $scope . componentState ;
228- if ( this . isStudentMode ( ) ) {
229- if ( this . UtilService . hasShowWorkConnectedComponent ( this . componentContent ) ) {
230- this . handleConnectedComponents ( ) ;
231- } else if (
232- this . DrawService . componentStateHasStudentWork ( componentState , this . componentContent )
233- ) {
234- this . setStudentWork ( componentState ) ;
235- } else if ( this . UtilService . hasConnectedComponent ( this . componentContent ) ) {
236- this . handleConnectedComponents ( ) ;
237- } else if (
238- componentState == null ||
239- ! this . DrawService . componentStateHasStudentWork ( componentState , this . componentContent )
240- ) {
241- if ( this . componentContent . starterDrawData != null ) {
242- this . drawingTool . load ( this . componentContent . starterDrawData ) ;
243- }
244- if ( this . componentContent . background != null ) {
245- this . drawingTool . setBackgroundImage ( this . componentContent . background ) ;
246- }
247- }
248- } else if ( this . isAuthoringComponentPreviewMode ( ) ) {
191+ if ( this . UtilService . hasShowWorkConnectedComponent ( this . componentContent ) ) {
192+ this . handleConnectedComponents ( ) ;
193+ } else if (
194+ this . DrawService . componentStateHasStudentWork ( componentState , this . componentContent )
195+ ) {
196+ this . setStudentWork ( componentState ) ;
197+ } else if ( this . UtilService . hasConnectedComponent ( this . componentContent ) ) {
198+ this . handleConnectedComponents ( ) ;
199+ } else if (
200+ componentState == null ||
201+ ! this . DrawService . componentStateHasStudentWork ( componentState , this . componentContent )
202+ ) {
249203 if ( this . componentContent . starterDrawData != null ) {
250204 this . drawingTool . load ( this . componentContent . starterDrawData ) ;
251205 }
252206 if ( this . componentContent . background != null ) {
253207 this . drawingTool . setBackgroundImage ( this . componentContent . background ) ;
254208 }
255- } else {
256- this . setStudentWork ( componentState ) ;
257209 }
258210
259211 if ( this . hasMaxSubmitCount ( ) && this . hasSubmitsLeft ( ) ) {
@@ -278,24 +230,16 @@ class DrawController extends ComponentController {
278230 500
279231 ) ;
280232
281- if ( this . isStudentMode ( ) ) {
282- this . drawingTool . on ( 'tool:changed' , ( toolName ) => {
283- const category = 'Tool' ;
284- const event = 'toolSelected' ;
285- const data = {
286- selectedToolName : toolName
287- } ;
288- this . StudentDataService . saveComponentEvent ( this , category , event , data ) ;
289- } ) ;
290- }
233+ this . drawingTool . on ( 'tool:changed' , ( toolName ) => {
234+ const category = 'Tool' ;
235+ const event = 'toolSelected' ;
236+ const data = {
237+ selectedToolName : toolName
238+ } ;
239+ this . StudentDataService . saveComponentEvent ( this , category , event , data ) ;
240+ } ) ;
291241
292- if ( this . isGradingMode ( ) || this . isGradingRevisionMode ( ) ) {
293- $ ( '#' + this . drawingToolId )
294- . find ( '.dt-tools' )
295- . hide ( ) ;
296- } else {
297- this . setupTools ( ) ;
298- }
242+ this . setupTools ( ) ;
299243
300244 if ( this . isDisabled ) {
301245 this . drawingTool . canvas . removeListeners ( ) ;
0 commit comments