@@ -18,6 +18,51 @@ define([
18
18
] , function ( com_String , PopupComponent ) {
19
19
20
20
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
+ """`
21
66
22
67
/**
23
68
* Comment
@@ -29,9 +74,13 @@ define([
29
74
this . config . dataview = false ;
30
75
this . config . codeview = false ;
31
76
this . config . saveOnly = true ;
77
+ this . selectBoxClassName = 'vp-ct-option' ; // Select Box ClassName
78
+ this . selectOptionPrefix = 'vp_template_' ; // Select Options Class Prefix Name
32
79
33
80
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 } ,
35
84
...this . state
36
85
}
37
86
@@ -40,14 +89,45 @@ define([
40
89
41
90
_bindEvent ( ) {
42
91
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
+ } ) ;
44
112
}
45
113
46
114
templateForBody ( ) {
47
115
/** Implement generating template */
48
116
var page = new com_String ( ) ;
49
117
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
+
51
131
return page . toString ( ) ;
52
132
}
53
133
0 commit comments