@@ -7,6 +7,8 @@ import RaisedButton from 'material-ui/RaisedButton';
7
7
import FontIcon from 'material-ui/FontIcon' ;
8
8
import IconButton from 'material-ui/IconButton' ;
9
9
import Snackbar from 'material-ui/Snackbar' ;
10
+ import Cookies from 'js-cookie' ;
11
+ import slugify from 'slugify' ;
10
12
11
13
import getMuiTheme from 'material-ui/styles/getMuiTheme' ;
12
14
// https://github.com/JedWatson/react-select
@@ -179,6 +181,8 @@ class AddComment extends React.Component {
179
181
this . moveTagBlock = this . moveTagBlock . bind ( this ) ;
180
182
this . onTagValueChange = this . onTagValueChange . bind ( this ) ;
181
183
this . onIsMentionedInLemmaChange = this . onIsMentionedInLemmaChange . bind ( this ) ;
184
+ this . selectTagType = this . selectTagType . bind ( this ) ;
185
+ this . addNewTag = this . addNewTag . bind ( this ) ;
182
186
}
183
187
184
188
_enableButton ( ) {
@@ -269,8 +273,8 @@ class AddComment extends React.Component {
269
273
// TODO: form validation
270
274
// TODO: Migrate to formsy components
271
275
const error = this . validateStateForSubmit ( ) ;
272
- this . showSnackBar ( error ) ;
273
- if ( error . errors ) {
276
+ if ( error ) {
277
+ this . showSnackBar ( error ) ;
274
278
return false ;
275
279
}
276
280
@@ -309,9 +313,10 @@ class AddComment extends React.Component {
309
313
}
310
314
311
315
showSnackBar ( error ) {
316
+ console . log ( "error LOG" , error ) ;
312
317
this . setState ( {
313
- snackbarOpen : error . errors ,
314
- snackbarMessage : error . errorMessage ,
318
+ snackbarOpen : true ,
319
+ snackbarMessage : error . message ,
315
320
} ) ;
316
321
setTimeout ( ( ) => {
317
322
this . setState ( {
@@ -322,7 +327,7 @@ class AddComment extends React.Component {
322
327
323
328
validateStateForSubmit ( ) {
324
329
let errors = false ;
325
- let errorMessage = 'Missing comment data: ' ;
330
+ let errorMessage = '' ;
326
331
if ( ! this . state . titleValue ) {
327
332
errors = true ;
328
333
errorMessage += ' title,' ;
@@ -341,12 +346,9 @@ class AddComment extends React.Component {
341
346
}
342
347
if ( errors === true ) {
343
348
errorMessage = errorMessage . slice ( 0 , - 1 ) ;
344
- errorMessage += '.' ;
349
+ errorMessage = new Meteor . Error ( 'data-missing' , 'Missing comment data:' . concat ( errorMessage , '.' ) ) ;
345
350
}
346
- return {
347
- errors,
348
- errorMessage,
349
- } ;
351
+ return errorMessage ;
350
352
}
351
353
352
354
addReferenceWorkBlock ( ) {
@@ -440,6 +442,40 @@ class AddComment extends React.Component {
440
442
} ) ;
441
443
}
442
444
445
+ selectTagType ( tagId , event , index ) {
446
+ const currentTags = this . state . tagsValue ;
447
+ currentTags [ index ] . keyword . type = event . target . value ;
448
+ this . setState ( {
449
+ tagsValue : currentTags
450
+ } ) ;
451
+
452
+ Meteor . call ( 'keywords.changeType' , Cookies . get ( 'loginToken' ) , tagId , event . target . value , ( err ) => {
453
+ if ( err ) {
454
+ this . showSnackBar ( err ) ;
455
+ } else {
456
+ this . showSnackBar ( { message : 'Keyword type changed' } ) ;
457
+ }
458
+ } ) ;
459
+ }
460
+
461
+ addNewTag ( tag ) {
462
+
463
+ const keyword = [ {
464
+ title : tag . value ,
465
+ slug : slugify ( tag . value . toLowerCase ( ) ) ,
466
+ type : 'word' ,
467
+ count : 1 ,
468
+ tenantId : Session . get ( 'tenantId' ) ,
469
+ } ] ;
470
+
471
+ Meteor . call ( 'keywords.insert' , Cookies . get ( 'loginToken' ) , keyword , ( err ) => {
472
+ if ( err ) {
473
+ this . showSnackBar ( err ) ;
474
+ } else {
475
+ this . showSnackBar ( { message : 'Tag added' } ) ;
476
+ }
477
+ } ) ;
478
+ }
443
479
// --- END SUBMIT / VALIDATION HANDLE --- //
444
480
445
481
render ( ) {
@@ -468,7 +504,7 @@ class AddComment extends React.Component {
468
504
value = { this . state . commenterValue }
469
505
onChange = { this . onCommenterValueChange }
470
506
placeholder = "Commentator..."
471
- multi = { true }
507
+ multi
472
508
/>
473
509
:
474
510
''
@@ -492,6 +528,8 @@ class AddComment extends React.Component {
492
528
moveTagBlock = { this . moveTagBlock }
493
529
onTagValueChange = { this . onTagValueChange }
494
530
onIsMentionedInLemmaChange = { this . onIsMentionedInLemmaChange }
531
+ selectTagType = { this . selectTagType }
532
+ addNewTag = { this . addNewTag }
495
533
/>
496
534
497
535
</ div >
@@ -542,6 +580,7 @@ class AddComment extends React.Component {
542
580
value : rW . value ,
543
581
label : rW . label ,
544
582
slug : rW . slug ,
583
+ type : rW . type ,
545
584
i,
546
585
} ) ;
547
586
} ) ;
0 commit comments