@@ -18,6 +18,51 @@ define([
1818] , function ( com_String , PopupComponent ) {
1919
2020 const COMMENT_DEFAULT_CODE = '# Write down comments'
21+ // Templates from NumPy Style Python Docstrings.
22+ const COMMENT_CLASS_TEMPLATE =
23+ `"""Summarize the class in one line.
24+ Several sentences ...
25+ providing an extended description.
26+ Note
27+ ----------
28+ Note about this class.
29+ Parameters
30+ ----------
31+ param1 : param_type
32+ Parameter description.
33+ param2 : param_type
34+ Parameter description.
35+ Attributes
36+ ----------
37+ attr1 : attr_type
38+ Attibute description.
39+ attr2 : attr_type
40+ Attibute description.
41+ Examples
42+ ----------
43+
44+ References
45+ ----------
46+ """`
47+ const COMMENT_METHOD_TEMPLATE =
48+ `"""Summarize the function in one line.
49+ Several sentences ...
50+ providing an extended description.
51+ Parameters
52+ ----------
53+ param1 : param_type
54+ Parameter description.
55+ param2 : param_type
56+ Parameter description.
57+ Returns
58+ -------
59+ return_type
60+ Return description.
61+ Note
62+ ----------
63+ Examples
64+ ----------
65+ """`
2166
2267 /**
2368 * Comment
@@ -29,9 +74,13 @@ define([
2974 this . config . dataview = false ;
3075 this . config . codeview = false ;
3176 this . config . saveOnly = true ;
77+ this . selectBoxClassName = 'vp-ct-option' ; // Select Box ClassName
78+ this . selectOptionPrefix = 'vp_template_' ; // Select Options Class Prefix Name
3279
3380 this . state = {
34- code : COMMENT_DEFAULT_CODE ,
81+ v1 : { "name" : "Default" , "code" : COMMENT_DEFAULT_CODE } ,
82+ v2 : { "name" : "Class" , "code" : COMMENT_CLASS_TEMPLATE } ,
83+ v3 : { "name" : "Method" , "code" : COMMENT_METHOD_TEMPLATE } ,
3584 ...this . state
3685 }
3786
@@ -40,14 +89,45 @@ define([
4089
4190 _bindEvent ( ) {
4291 super . _bindEvent ( ) ;
43- /** Implement binding events */
92+
93+ var commentTemplates = this . state ;
94+ let cmCodeListTemp = this . cmCodeList ;
95+
96+ $ ( '.' + this . selectBoxClassName ) . on ( 'change' , function ( ) {
97+ // get code mirror object
98+ let targetCmObj = cmCodeListTemp . filter ( obj => obj . key == 'code' ) ;
99+ let cm = targetCmObj [ 0 ] . cm ;
100+ var templateOption = $ ( this ) . val ( ) ;
101+
102+ // Change Code Mirror Text
103+ if ( templateOption == commentTemplates . v1 [ 'name' ] ) {
104+ cm . setValue ( commentTemplates . v1 [ 'code' ] ) ;
105+ } else if ( templateOption == commentTemplates . v2 [ 'name' ] ) {
106+ cm . setValue ( commentTemplates . v2 [ 'code' ] ) ;
107+ } else if ( templateOption == commentTemplates . v3 [ 'name' ] ) {
108+ cm . setValue ( commentTemplates . v3 [ 'code' ] ) ;
109+ }
110+ cm . save ( ) ;
111+ } ) ;
44112 }
45113
46114 templateForBody ( ) {
47115 /** Implement generating template */
48116 var page = new com_String ( ) ;
49117 page . appendFormatLine ( '<textarea name="code" class="code vp-state" id="code">{0}</textarea>'
50- , this . state . code ) ;
118+ , this . state . v1 [ 'code' ] ) ;
119+
120+ // add select box
121+ page . appendFormatLine ( '<select class="vp-select w100 {0}" >' , this . selectBoxClassName ) ;
122+ for ( var key in this . state ) {
123+ var optionName = this . state [ key ] [ 'name' ] ;
124+ page . appendFormatLine ( '<option value="{0}" id="{1}">{2}</option>' ,
125+ optionName ,
126+ this . selectOptionPrefix + optionName ,
127+ optionName ) ;
128+ }
129+ page . appendFormatLine ( '</select>' ) ;
130+
51131 return page . toString ( ) ;
52132 }
53133
0 commit comments