diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js
index 53bfcb1..1c84ff8 100644
--- a/web/pgadmin/static/js/backform.pgadmin.js
+++ b/web/pgadmin/static/js/backform.pgadmin.js
@@ -1154,6 +1154,96 @@
}
});
+
+ /*
+ * SQL Field Control to write/edit SQL query for the specific node.
+ */
+ var SqlFieldControl = Backform.SqlFieldControl = Backform.Control.extend({
+ defaults: {
+ label: "",
+ controlsClassName: "pgadmin-controls col-sm-12",
+ extraClasses: [],
+ helpMessage: null
+ },
+ template: _.template([
+ '',
+ '
',
+ ' ',
+ ' <% if (helpMessage && helpMessage.length) { %>',
+ ' <%=helpMessage%>',
+ ' <% } %>',
+ '
'
+ ].join("\n")),
+ events: {
+ "change textarea": "setSqlData",
+ "blur textarea": "setSqlData"
+ },
+ setSqlData: function(){
+ var name = this.field.get('name'),
+ value = this.sqlField.getValue();
+ this.model.set(name, value);
+ this.sqlField.setValue(value);
+ },
+ /*
+ * Initialize the SQL Field control properly
+ */
+ initialize: function(o) {
+ Backform.Control.prototype.initialize.apply(this, arguments);
+ /*
+ * We will listen to the tab change event to check, if the SQL tab has
+ * been clicked or, not. if clicked refresh sqlField variable
+ */
+ this.model.on('pg-property-tab-changed', this.onTabChange, this);
+ },
+ getValueFromDOM: function() {
+ return this.formatter.toRaw(this.$el.find("textarea").val(), this.model);
+ },
+ /*
+ * Find input fields having name attribute
+ * thus, it skips textarea with no name attribute
+ * which we don't need.
+ */
+ updateInvalid: function() {
+ var self = this,
+ errorModel = this.model.errorModel;
+
+ if (!(errorModel instanceof Backbone.Model)) return this;
+
+ this.clearInvalid();
+
+ this.$el.find(':input[name]').not('button').each(function(ix, el) {
+ var attrArr = $(el).attr('name').split('.'),
+ name = attrArr.shift(),
+ path = attrArr.join('.'),
+ error = self.keyPathAccessor(errorModel.toJSON(), $(el).attr('name'));
+
+ if (_.isEmpty(error)) return;
+
+ self.$el.addClass(Backform.errorClassName).append(
+ $("").addClass('pgadmin-control-error-message col-xs-12 help-block').text(error)
+ );
+ });
+ },
+ render: function() {
+ // Use the Backform Control's render function
+ Backform.Control.prototype.render.apply(this, arguments);
+ var sqlField = CodeMirror.fromTextArea(
+ (this.$el.find("textarea")[0]), {
+ lineNumbers: true,
+ mode: "text/x-sql",
+ readOnly: false
+ });
+ //Refresh sqlField to refresh the control right after it renders
+ this.sqlField = sqlField;
+ setTimeout(function() {
+ sqlField.refresh();
+ }, 100);
+ return this;
+ },
+ onTabChange: function(obj) {
+ this.sqlField.refresh();
+ }
+});
/*
* Integer input Control functionality just like backgrid
*/