@@ -22,6 +22,95 @@ modAIAdmin.panel.Tool = function (config) {
2222 items : configItems ,
2323 } ) ;
2424
25+ this . promptField = new Ext . form . TextArea ( {
26+ fieldLabel : _ ( 'modai.admin.tool.prompt' ) ,
27+ name : 'prompt' ,
28+ msgTarget : 'under' ,
29+ value : config . record . prompt || config . record . defaultPrompt ,
30+ disabled : ! config . record . prompt ,
31+ allowBlank : true ,
32+ grow : true ,
33+ defaultPrompt : config . record . defaultPrompt ,
34+ editBtn : null ,
35+ resetBtn : null ,
36+ renderEditButton : function ( ) {
37+ if ( this . editBtn ) {
38+ return ;
39+ }
40+
41+ const btn = document . createElement ( 'button' ) ;
42+ btn . type = 'button' ;
43+ btn . className = 'modai-admin-label_button' ;
44+ btn . title = 'Edit Prompt' ;
45+ btn . addEventListener ( 'click' , ( ) => {
46+ this . enable ( ) ;
47+ btn . remove ( ) ;
48+ this . editBtn = null ;
49+
50+ this . renderResetButton ( ) ;
51+ } ) ;
52+
53+ const i = document . createElement ( 'i' ) ;
54+ i . className = 'icon icon-edit' ;
55+ btn . appendChild ( i ) ;
56+
57+ this . editBtn = btn ;
58+ this . label . dom . append ( btn ) ;
59+ } ,
60+ renderResetButton : function ( ) {
61+ if ( this . resetBtn ) {
62+ return ;
63+ }
64+
65+ const btn = document . createElement ( 'button' ) ;
66+ btn . type = 'button' ;
67+ btn . className = 'modai-admin-label_button' ;
68+ btn . title = 'Reset to the default Prompt' ;
69+ btn . addEventListener ( 'click' , ( ) => {
70+ this . setValue ( this . defaultPrompt )
71+ this . disable ( ) ;
72+ btn . remove ( ) ;
73+ this . resetBtn = null ;
74+
75+ this . renderEditButton ( ) ;
76+ } ) ;
77+
78+ const i = document . createElement ( 'i' ) ;
79+ i . className = 'icon icon-refresh' ;
80+ btn . appendChild ( i ) ;
81+
82+ this . resetBtn = btn ;
83+ this . label . dom . append ( btn ) ;
84+ } ,
85+ initPrompt : function ( prompt , defaultPrompt ) {
86+ this . defaultPrompt = defaultPrompt ;
87+ if ( this . editBtn ) {
88+ this . editBtn . remove ( ) ;
89+ this . editBtn = null ;
90+ }
91+
92+ if ( this . resetBtn ) {
93+ this . resetBtn . remove ( ) ;
94+ this . resetBtn = null ;
95+ }
96+
97+ if ( prompt ) {
98+ this . setValue ( prompt ) ;
99+ this . renderResetButton ( ) ;
100+ return ;
101+ }
102+
103+ this . disable ( ) ;
104+ this . setValue ( this . defaultPrompt ) ;
105+ this . renderEditButton ( ) ;
106+ } ,
107+ listeners : {
108+ afterrender : function ( ) {
109+ this . initPrompt ( config . record . prompt , config . record . defaultPrompt ) ;
110+ }
111+ }
112+ } ) ;
113+
25114 Ext . applyIf ( config , {
26115 border : false ,
27116 cls : 'container' ,
@@ -44,6 +133,7 @@ modAIAdmin.panel.Tool = function (config) {
44133
45134Ext . extend ( modAIAdmin . panel . Tool , MODx . FormPanel , {
46135 configSection : null ,
136+ promptField : null ,
47137
48138 success : function ( o , r ) {
49139 if ( this . config . isUpdate === false ) {
@@ -136,6 +226,8 @@ Ext.extend(modAIAdmin.panel.Tool, MODx.FormPanel, {
136226 description . setValue ( record . data . description ) ;
137227 }
138228
229+ this . promptField . initPrompt ( undefined , record . data . defaultPrompt ) ;
230+
139231 this . configSection . removeAll ( ) ;
140232 Object . entries ( record . data . config ) . forEach ( ( [ key , config ] ) => {
141233 this . configSection . add ( modAIAdmin . formatConfigItem ( key , config ) ) ;
@@ -154,13 +246,14 @@ Ext.extend(modAIAdmin.panel.Tool, MODx.FormPanel, {
154246 value : config . record . name ,
155247 } ,
156248 {
157- fieldLabel : _ ( 'modai.admin.context_provider .description' ) ,
249+ fieldLabel : _ ( 'modai.admin.tool .description' ) ,
158250 xtype : 'textarea' ,
159251 name : 'description' ,
160252 msgTarget : 'under' ,
161253 value : config . record . description ,
162254 allowBlank : true ,
163255 } ,
256+ this . promptField
164257 ] ,
165258 } ,
166259
0 commit comments