@@ -30,21 +30,24 @@ function addNewSection(tab,id,section,sec){
3030} 
3131
3232function  loadHint ( name ) { 
33-   $ . ajax ( '/hint/' + name ) . then ( function ( data ) { 
33+   $ . ajax ( '/hint/' + name ) 
34+   . fail ( ajaxAlert ) 
35+   . then ( function ( data ) { 
3436    $ ( '.mct-hint' ) . html ( data ) ; 
3537  } ) 
3638} 
3739function  loadGcode ( name ) { 
38-   $ . ajax ( '/gcode/' + name ) . then ( function ( data ) { 
40+   $ . ajax ( '/gcode/' + name ) 
41+   . fail ( ajaxAlert ) 
42+   . then ( function ( data ) { 
3943    $ ( '.mct-hint' ) . html ( data ) . prop ( 'scrollTop' , 0 ) ; 
4044  } ) 
4145} 
4246function  saveProp ( cmd ) { 
43- var  state = $ ( '.mct-status' ) 
44-   state . text ( 'saving...' ) . fadeIn ( ) . css ( { color :'black' } ) ; 
47+   progress ( 0 ) ( true ) ( '50%' ) ; 
4548  return  $ . post ( cmd ) 
46-   . then ( function ( a ) {  state . text ( 'saved' ) . fadeOut ( 1000 ) ;  return  a } ) 
47-   . fail ( function ( a ) {  state . text ( '' + a . responseJSON . code ) . css ( { color : 'red' } ) } ) 
49+   . then ( function ( a ) {  progress ( '100%' ) ( false ) ;  return  a } ) 
50+   . fail ( function ( e ) {  progress ( 1 ) ( 'ERROR: ' + ( e . responseText || e . state ( ) ) ) ;   return   ajaxAlert ( e )   } ) ; 
4851} 
4952function  applyProp ( def , row , prop , val ) { 
5053  def . changed = def . changed || { } 
@@ -62,27 +65,29 @@ function getVal(ob,name){
6265      return  ob . changed [ name ] 
6366  return  ob [ name ] 
6467} 
68+ function  ajaxAlert ( fail ) { 
69+   _add ( $ ( 'template._alert' ) ) 
70+   . find ( 'p' ) . text ( fail . responseText || ( fail . statusText + ': ' + fail . state ( ) ) ) 
71+   return  fail ; 
72+ } 
6573function  cmdReload ( cmd , modal ) { 
6674    cmd 
6775    . then ( function ( data ) { 
6876      $ ( window ) . unbind ( 'beforeunload' ) ; 
6977      window . location . reload ( ) ; 
7078    } ) 
71-     . fail ( function ( a ) { 
79+     . fail ( function ( e ) { 
7280      modal && modal . modal ( 'hide' ) 
73-       _add ( $ ( 'template._alert' ) ) 
74-       . find ( 'p' ) . text ( a . responseText ) 
81+       return  ajaxAlert ( e ) ; 
7582    } ) 
7683} 
7784function  progress ( val ) { 
7885    var  dom  =  $ ( '.mct-progress' ) ; 
7986    val === true && dom . toggle ( val ) ; 
80-     val === false && dom . fadeOut ( 5000 ) ; 
81-     if  ( typeof  val  == 'string' ) { 
82-       dom . find ( 'span' ) . text ( val ) 
83-       $ ( '.mct-progress .progress-bar' ) . width ( val ) ; 
84-     } 
85-     typeof  val  == 'number' &&  dom . find ( '.progress-bar' ) . toggleClass ( 'progress-bar-danger' , ! ! val ) ; 
87+     val === false && dom . stop ( ) . fadeOut ( 3000 ) ; 
88+     if  ( typeof  val  == 'string' ) 
89+       dom . find ( '.progress-bar' ) . width ( val ) . find ( 'span' ) . text ( val ) ; 
90+     typeof  val  == 'number' &&  dom . find ( '.progress-bar' ) . toggleClass ( 'bg-danger' , ! ! val ) ; 
8691    return  progress ; 
8792} 
8893// The plugin code https://gist.github.com/meleyal/3794126 
@@ -105,7 +110,6 @@ $.fn.draghover = function(options) {
105110  } ) ; 
106111} ; 
107112function  upload_files ( files ) { 
108- //  return new Promise((done,fail)=>{ 
109113    if  (  ! files . length  ) 
110114      return  ; //fail('no files') 
111115    var  formData  =  new  FormData ( ) ; 
@@ -135,17 +139,14 @@ function upload_files(files){
135139            // once the upload reaches 100%, set the progress bar text to done 
136140            if  ( percentComplete  ===  100 ) { 
137141              progress ( false ) ; 
138- //              done(); 
139142            } 
140143          } 
141144        } ,  false ) ; 
142145        return  xhr ; 
143146      } 
144147    } ) . fail ( function ( e ) { 
145-       progress ( 1 ) ( 'ERROR ' + e . responseText ) ; 
146- //      fail(e.responseText) 
148+       progress ( 1 ) ( 'ERROR: ' + ( e . responseText || e . state ( ) ) ) ; 
147149    } ) ; 
148- //  }) 
149150} 
150151function  stream_cmd ( command , proc ) { 
151152    return  function ( ) { 
@@ -480,7 +481,6 @@ $(function(){
480481    } ) ; 
481482  ( function ( ) { 
482483    var  m = $ ( '#mct-tags-modal' ) ; 
483-     var  a = $ ( '#mct-alert' ) ; 
484484    var  t = m . find ( 'table tbody' ) ; 
485485    m . find ( 'button.btn-primary' ) . on ( 'click' , function ( ev ) { 
486486      var  row  =  t . find ( '.table-success' ) ; 
@@ -493,8 +493,10 @@ $(function(){
493493      $ ( this ) . find ( 'tr' ) . removeClass ( 'table-success' ) ; 
494494      $ ( ev . target ) . parents ( 'tr' ) . addClass ( 'table-success' ) 
495495    } ) ; 
496-     $ ( '.mct-tags' ) . on ( 'click' , function ( ) { 
497-       $ . ajax ( '/tags' ) . then ( function ( data ) { 
496+     $ ( '.mct-change' ) . on ( 'click' , function ( ) { 
497+       $ . ajax ( '/tags' ) 
498+       . fail ( ajaxAlert ) 
499+       . then ( function ( data ) { 
498500        data = data . sort ( function ( a , b ) {  return  a . date < b . date ?1 :a . date > b . date ?- 1 :0 ; } ) 
499501        t . empty ( ) ; 
500502        data . map ( function ( row ) { 
@@ -503,25 +505,34 @@ $(function(){
503505        m . modal ( ) ; 
504506      } ) 
505507    } ) 
506-   } ) ( ) ; 
507-   ( function ( ) { 
508-     var  r = $ ( '#mct-reset-modal' ) ; 
509-     var  p = r . find ( 'p' ) ; 
510-     $ ( '.mct-reset' ) . on ( 'click' , function ( ) { 
511-       $ . ajax ( '/status' ) . then ( function ( data ) { 
508+   } ( ) ) ; 
509+   ( function ( btn , ui ) { 
510+     var  p = ui . find ( 'p' ) ; 
511+     btn . on ( 'click' , function ( ) { 
512+       $ . ajax ( '/status' ) 
513+       . fail ( ajaxAlert ) 
514+       . then ( function ( data ) { 
512515        p . empty ( ) ; 
513516        data . files . map ( function ( file ) { 
514517          p . append ( file . path + '<br>' ) 
515518        } ) 
516-         r . modal ( ) ; 
519+         ui . modal ( ) ; 
517520      } ) 
518521    } ) 
519-     r . find ( 'button.btn-primary ' ) . on ( 'click' , function ( ev ) { 
520-         cmdReload ( $ . ajax ( '/checkout-force' ) , r ) ; 
522+     ui . find ( 'button.btn-danger ' ) . on ( 'click' , function ( ev ) { 
523+         cmdReload ( $ . ajax ( '/checkout-force' ) , ui ) ; 
521524    } ) 
522-   } ) ( ) ; 
525+   } ( $ ( '.mct-reset' ) , $ ( '#mct-reset-modal' ) ) ) ; 
526+   ( function ( btn ) { 
527+     btn . on ( 'click' , function ( ) { 
528+       progress ( 0 ) ( true ) ( '50%' ) ; 
529+       $ . ajax ( '/fetch' ) 
530+       . fail ( ajaxAlert ) 
531+       . then ( function ( a ) {  progress ( '100%' ) ( false ) ;  return  a } ) 
532+     } ) 
533+   } ( $ ( '.mct-update' ) ) ) ; 
523534  $ ( '.mct-consoles' ) . on ( 'click' , function ( ) {  window . open ( 'consoles.html' , '_blank' )  } ) ; 
524-   ( function ( ) { 
535+   ( function ( ) {   //REMOVE 
525536    var  r = $ ( '#mct-console-modal' ) ; 
526537    var  p = r . find ( 'textarea' ) ; 
527538    var  b = r . find ( '.modal-body button' ) ; 
@@ -612,7 +623,7 @@ $(function(){
612623    var  cmd ; 
613624    $ ( '.mct-pio-compile, .mct-pio-flash, .mct-ports a' ) 
614625    . toggleClass ( 'disabled' , ! config . pio ) 
615-     . attr ( config . pio ?'title' :'null' , '' ) 
626+     . attr ( ! config . pio ?'title' :'null' , 'PlatformIO not installed ' ) 
616627    . eq ( 0 ) . on ( 'click' , function ( ) { 
617628        cmd = stream_cmd ( '/pio' , proc ) ( ) 
618629    } ) . end ( ) 
@@ -676,7 +687,7 @@ $(function(){
676687  } ( ) ) ; 
677688    var  state = $ ( '.mct-changed input' ) 
678689    . on ( 'change' , function ( ) { 
679-       var  defs = $ ( '.tab-pane[id*=card] .form-group' ) 
690+       var  defs = $ ( '.tab-pane[id*=card-C ] .form-group' ) 
680691      if  ( $ ( this ) . prop ( 'checked' ) ) 
681692        defs . not ( '.bg-info' ) . hide ( ) 
682693      else 
0 commit comments