2015-10-28 22:36:09 +05:30
|
|
|
(function(root, factory) {
|
|
|
|
|
// Set up Backform appropriately for the environment. Start with AMD.
|
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
|
define(['underscore', 'jquery', 'backbone', 'backform', 'backgrid', 'alertify'],
|
|
|
|
|
function(_, $, Backbone, Backform, Backgrid, Alertify) {
|
|
|
|
|
// Export global even in AMD case in case this script is loaded with
|
|
|
|
|
// others that may still expect a global Backform.
|
|
|
|
|
return factory(root, _, $, Backbone, Backform, Alertify);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Next for Node.js or CommonJS. jQuery may not be needed as a module.
|
|
|
|
|
} else if (typeof exports !== 'undefined') {
|
|
|
|
|
var _ = require('underscore') || root._,
|
|
|
|
|
$ = root.jQuery || root.$ || root.Zepto || root.ender,
|
|
|
|
|
Backbone = require('backbone') || root.Backbone,
|
|
|
|
|
Backform = require('backform') || root.Backform;
|
|
|
|
|
Alertify = require('alertify') || root.Alertify;
|
|
|
|
|
factory(root, _, $, Backbone, Backform, Alertify);
|
|
|
|
|
|
|
|
|
|
// Finally, as a browser global.
|
|
|
|
|
} else {
|
|
|
|
|
factory(root, root._, (root.jQuery || root.Zepto || root.ender || root.$), root.Backbone, root.Backform);
|
|
|
|
|
}
|
|
|
|
|
} (this, function(root, _, $, Backbone, Backform, Alertify) {
|
2016-02-05 14:35:49 +05:30
|
|
|
/*
|
|
|
|
|
* Add mechanism in backgrid to render different types of cells in
|
|
|
|
|
* same column;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Add new property cellFunction in Backgrid.Column.
|
|
|
|
|
_.extend(Backgrid.Column.prototype.defaults, { cellFunction: undefined });
|
|
|
|
|
|
|
|
|
|
_.extend(Backgrid.Row.prototype, {
|
|
|
|
|
makeCell: function (column) {
|
|
|
|
|
return new (this.getCell(column))({
|
|
|
|
|
column: column,
|
|
|
|
|
model: this.model
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
/*
|
|
|
|
|
* getCell function will check and execute user given cellFunction to get
|
|
|
|
|
* appropriate cell class for current cell being rendered.
|
|
|
|
|
* User provided cellFunction must return valid cell class.
|
|
|
|
|
* cellFunction will be called with context (this) as column and model as
|
|
|
|
|
* argument.
|
|
|
|
|
*/
|
|
|
|
|
getCell: function (column) {
|
|
|
|
|
var cf = column.get("cellFunction");
|
|
|
|
|
if (_.isFunction(cf)){
|
|
|
|
|
var cell = cf.apply(column, [this.model]);
|
|
|
|
|
try {
|
|
|
|
|
return Backgrid.resolveNameToClass(cell, "Cell");
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (e instanceof ReferenceError) {
|
|
|
|
|
// Fallback to column cell.
|
|
|
|
|
return column.get("cell");
|
|
|
|
|
} else {
|
|
|
|
|
throw e; // Let other exceptions bubble up
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return column.get("cell");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-28 22:36:09 +05:30
|
|
|
var ObjectCellEditor = Backgrid.Extension.ObjectCellEditor = Backgrid.CellEditor.extend({
|
|
|
|
|
modalTemplate: _.template([
|
2015-10-30 02:02:40 +05:30
|
|
|
'<div class="subnode-dialog" tabindex="1">',
|
2015-10-28 22:36:09 +05:30
|
|
|
' <div class="subnode-body"></div>',
|
|
|
|
|
'</div>'
|
|
|
|
|
].join("\n")),
|
|
|
|
|
stringTemplate: _.template([
|
|
|
|
|
'<div class="form-group">',
|
|
|
|
|
' <label class="control-label col-sm-4"><%=label%></label>',
|
|
|
|
|
' <div class="col-sm-8">',
|
|
|
|
|
' <input type="text" class="form-control" name="<%=name%>" value="<%=value%>" placeholder="<%=placeholder%>" />',
|
|
|
|
|
' </div>',
|
|
|
|
|
'</div>'
|
|
|
|
|
].join("\n")),
|
|
|
|
|
extendWithOptions: function(options) {
|
|
|
|
|
_.extend(this, options);
|
|
|
|
|
},
|
|
|
|
|
render: function () {
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
postRender: function(model, column) {
|
|
|
|
|
var editor = this,
|
|
|
|
|
el = this.el;
|
|
|
|
|
columns_length = this.columns_length;
|
|
|
|
|
|
|
|
|
|
if (column != null && column.get("name") != this.column.get("name"))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!_.isArray(this.schema)) throw new TypeError("schema must be an array");
|
|
|
|
|
|
|
|
|
|
// Create a Backbone model from our object if it does not exist
|
|
|
|
|
var $dialog = this.createDialog(columns_length);
|
|
|
|
|
|
|
|
|
|
// Add the Bootstrap form
|
|
|
|
|
var $form = $('<form class="form-dialog"></form>');
|
|
|
|
|
$dialog.find('div.subnode-body').append($form);
|
|
|
|
|
|
|
|
|
|
// Call Backform to prepare dialog
|
|
|
|
|
back_el = $dialog.find('form.form-dialog');
|
|
|
|
|
|
2015-10-30 02:02:40 +05:30
|
|
|
this.objectView = new Backform.Dialog({
|
2015-10-28 22:36:09 +05:30
|
|
|
el: back_el, model: this.model, schema: this.schema,
|
2015-10-30 02:02:40 +05:30
|
|
|
tabPanelClassName: function() {
|
|
|
|
|
return 'sub-node-form col-sm-12';
|
|
|
|
|
}
|
2015-10-28 22:36:09 +05:30
|
|
|
});
|
|
|
|
|
|
2015-10-30 02:02:40 +05:30
|
|
|
this.objectView.render();
|
2015-10-28 22:36:09 +05:30
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
createDialog: function(noofcol) {
|
2015-10-30 02:02:40 +05:30
|
|
|
var $dialog = this.$dialog = $(this.modalTemplate({title: ""})),
|
2015-10-28 22:36:09 +05:30
|
|
|
tr = $("<tr>"),
|
2015-10-30 02:02:40 +05:30
|
|
|
noofcol = noofcol || 1,
|
2015-10-28 22:36:09 +05:30
|
|
|
td = $("<td>", {class: 'editable sortable renderable', style: 'height: auto', colspan: noofcol+2}).appendTo(tr);
|
|
|
|
|
|
2015-10-30 02:02:40 +05:30
|
|
|
this.tr = tr;
|
2015-10-28 22:36:09 +05:30
|
|
|
|
|
|
|
|
// Show the Bootstrap modal dialog
|
|
|
|
|
td.append($dialog.css('display', 'block'));
|
|
|
|
|
this.el.parent('tr').after(tr);
|
|
|
|
|
|
|
|
|
|
return $dialog;
|
|
|
|
|
},
|
2015-10-30 02:02:40 +05:30
|
|
|
save: function() {
|
2015-10-28 22:36:09 +05:30
|
|
|
// Retrieve values from the form, and store inside the object model
|
2015-10-30 02:02:40 +05:30
|
|
|
this.model.trigger("backgrid:edited", this.model, this.column, new Backgrid.Command({keyCode:13}));
|
|
|
|
|
if (this.tr) {
|
|
|
|
|
this.tr.remove();
|
|
|
|
|
}
|
2015-10-28 22:36:09 +05:30
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
remove: function() {
|
2016-05-12 15:47:12 +05:30
|
|
|
this.objectView.remove();
|
2015-10-28 22:36:09 +05:30
|
|
|
Backgrid.CellEditor.prototype.remove.apply(this, arguments);
|
2015-10-30 02:02:40 +05:30
|
|
|
if (this.tr) {
|
|
|
|
|
this.tr.remove();
|
|
|
|
|
}
|
2015-10-28 22:36:09 +05:30
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var PGSelectCell = Backgrid.Extension.PGSelectCell = Backgrid.SelectCell.extend({
|
|
|
|
|
// It's possible to render an option group or use a
|
|
|
|
|
// function to provide option values too.
|
|
|
|
|
optionValues: function() {
|
|
|
|
|
var res = [];
|
|
|
|
|
opts = _.result(this.column.attributes, 'options');
|
|
|
|
|
_.each(opts, function(o) {
|
|
|
|
|
res.push([o.label, o.value]);
|
|
|
|
|
});
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var ObjectCell = Backgrid.Extension.ObjectCell = Backgrid.Cell.extend({
|
|
|
|
|
editorOptionDefaults: {
|
|
|
|
|
schema: []
|
|
|
|
|
},
|
|
|
|
|
className: "edit-cell",
|
|
|
|
|
editor: ObjectCellEditor,
|
|
|
|
|
initialize: function(options) {
|
|
|
|
|
Backgrid.Cell.prototype.initialize.apply(this, arguments);
|
|
|
|
|
|
|
|
|
|
// Pass on cell options to the editor
|
|
|
|
|
var cell = this,
|
|
|
|
|
editorOptions = {};
|
|
|
|
|
_.each(this.editorOptionDefaults, function(def, opt) {
|
|
|
|
|
if (!cell[opt]) cell[opt] = def;
|
|
|
|
|
if (options && options[opt]) cell[opt] = options[opt];
|
|
|
|
|
editorOptions[opt] = cell[opt];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
editorOptions['el'] = $(this.el);
|
2015-10-30 02:02:40 +05:30
|
|
|
editorOptions['columns_length'] = this.column.collection.length;
|
2015-10-30 13:07:09 +05:30
|
|
|
editorOptions['el'].attr('tabindex' , 1);
|
2015-10-28 22:36:09 +05:30
|
|
|
|
|
|
|
|
this.listenTo(this.model, "backgrid:edit", function (model, column, cell, editor) {
|
|
|
|
|
if (column.get("name") == this.column.get("name"))
|
|
|
|
|
editor.extendWithOptions(editorOptions);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
enterEditMode: function () {
|
2016-03-22 17:04:46 +00:00
|
|
|
// Notify that we are about to enter in edit mode for current cell.
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
// We will check if this row is editable first
|
|
|
|
|
var canEditRow = (!_.isUndefined(this.column.get('canEditRow')) &&
|
|
|
|
|
_.isFunction(this.column.get('canEditRow'))) ?
|
|
|
|
|
Backgrid.callByNeed(this.column.get('canEditRow'),
|
|
|
|
|
this.column, this.model) : true;
|
|
|
|
|
if (canEditRow) {
|
|
|
|
|
// Notify that we are about to enter in edit mode for current cell.
|
|
|
|
|
this.model.trigger("enteringEditMode", [this]);
|
|
|
|
|
|
|
|
|
|
Backgrid.Cell.prototype.enterEditMode.apply(this, arguments);
|
|
|
|
|
/* Make sure - we listen to the click event */
|
|
|
|
|
this.delegateEvents();
|
|
|
|
|
var editable = Backgrid.callByNeed(this.column.editable(), this.column, this.model);
|
|
|
|
|
|
|
|
|
|
if (editable) {
|
|
|
|
|
this.$el.html(
|
|
|
|
|
"<i class='fa fa-pencil-square subnode-edit-in-process'></i>"
|
|
|
|
|
);
|
|
|
|
|
this.model.trigger(
|
|
|
|
|
"pg-sub-node:opened", this.model, this
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Alertify.alert("This object is not editable by user",
|
|
|
|
|
function(){
|
|
|
|
|
return true;
|
|
|
|
|
});
|
2015-10-30 02:02:40 +05:30
|
|
|
}
|
2015-10-28 22:36:09 +05:30
|
|
|
},
|
|
|
|
|
render: function(){
|
|
|
|
|
this.$el.empty();
|
|
|
|
|
this.$el.html("<i class='fa fa-pencil-square-o'></i>");
|
|
|
|
|
this.delegateEvents();
|
2015-10-30 13:07:09 +05:30
|
|
|
if (this.grabFocus)
|
|
|
|
|
this.$el.focus();
|
2015-10-28 22:36:09 +05:30
|
|
|
return this;
|
2015-10-30 02:02:40 +05:30
|
|
|
},
|
|
|
|
|
exitEditMode: function() {
|
|
|
|
|
var index = $(this.currentEditor.objectView.el)
|
|
|
|
|
.find('.nav-tabs > .active > a[data-toggle="tab"]').first()
|
|
|
|
|
.data('tabIndex');
|
|
|
|
|
Backgrid.Cell.prototype.exitEditMode.apply(this, arguments);
|
|
|
|
|
this.model.trigger(
|
|
|
|
|
"pg-sub-node:closed", this, index
|
|
|
|
|
);
|
2015-10-30 13:07:09 +05:30
|
|
|
this.grabFocus = true;
|
2015-10-30 02:02:40 +05:30
|
|
|
},
|
|
|
|
|
events: {
|
|
|
|
|
'click': function(e) {
|
|
|
|
|
if (this.$el.find('i').first().hasClass('subnode-edit-in-process')) {
|
|
|
|
|
// Need to redundantly undelegate events for Firefox
|
|
|
|
|
this.undelegateEvents();
|
|
|
|
|
this.currentEditor.save();
|
|
|
|
|
} else {
|
|
|
|
|
this.enterEditMode.call(this, []);
|
|
|
|
|
}
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
2015-10-28 22:36:09 +05:30
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var DeleteCell = Backgrid.Extension.DeleteCell = Backgrid.Cell.extend({
|
|
|
|
|
/** @property */
|
|
|
|
|
className: "delete-cell",
|
|
|
|
|
events: {
|
|
|
|
|
"click": "deleteRow"
|
|
|
|
|
},
|
|
|
|
|
deleteRow: function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
that = this;
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
// We will check if row is deletable or not
|
|
|
|
|
var canDeleteRow = (!_.isUndefined(this.column.get('canDeleteRow')) &&
|
|
|
|
|
_.isFunction(this.column.get('canDeleteRow')) ) ?
|
|
|
|
|
Backgrid.callByNeed(this.column.get('canDeleteRow'),
|
|
|
|
|
this.column, this.model) : true;
|
|
|
|
|
if (canDeleteRow) {
|
|
|
|
|
Alertify.confirm(
|
2015-10-28 22:36:09 +05:30
|
|
|
'Delete Row',
|
2016-02-25 11:58:02 +00:00
|
|
|
'Are you sure you wish to delete this row?',
|
2015-10-28 22:36:09 +05:30
|
|
|
function(evt) {
|
|
|
|
|
that.model.collection.remove(that.model);
|
|
|
|
|
},
|
|
|
|
|
function(evt) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
);
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
} else {
|
|
|
|
|
Alertify.alert("This object can not be deleted",
|
|
|
|
|
function(){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-10-28 22:36:09 +05:30
|
|
|
},
|
|
|
|
|
initialize: function () {
|
|
|
|
|
Backgrid.Cell.prototype.initialize.apply(this, arguments);
|
|
|
|
|
},
|
|
|
|
|
render: function () {
|
|
|
|
|
this.$el.empty();
|
|
|
|
|
this.$el.html("<i class='fa fa-trash'></i>");
|
|
|
|
|
this.delegateEvents();
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2015-12-04 15:49:08 +05:30
|
|
|
var CustomHeaderCell = Backgrid.Extension.CustomHeaderCell = Backgrid.HeaderCell.extend({
|
2015-12-17 19:18:42 +05:30
|
|
|
initialize: function () {
|
|
|
|
|
// Here, we will add custom classes to header cell
|
|
|
|
|
Backgrid.HeaderCell.prototype.initialize.apply(this, arguments);
|
|
|
|
|
var getClassName = this.column.get('cellHeaderClasses');
|
|
|
|
|
if (getClassName) {
|
|
|
|
|
this.$el.addClass(getClassName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
SwitchCell renders a Bootstrap Switch in backgrid cell
|
|
|
|
|
*/
|
|
|
|
|
var SwitchCell = Backgrid.Extension.SwitchCell = Backgrid.BooleanCell.extend({
|
|
|
|
|
defaults: {
|
|
|
|
|
options: _.defaults({
|
|
|
|
|
onText: 'True',
|
|
|
|
|
offText: 'False',
|
|
|
|
|
onColor: 'success',
|
|
|
|
|
offColor: 'default',
|
|
|
|
|
size: 'mini'
|
|
|
|
|
}, $.fn.bootstrapSwitch.defaults)
|
|
|
|
|
},
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
|
2015-12-17 19:18:42 +05:30
|
|
|
className: 'switch-cell',
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
|
Backgrid.BooleanCell.prototype.initialize.apply(this, arguments);
|
|
|
|
|
this.onChange = this.onChange.bind(this);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
enterEditMode: function() {
|
|
|
|
|
this.$el.addClass('editor');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
exitEditMode: function() {
|
|
|
|
|
this.$el.removeClass('editor');
|
|
|
|
|
},
|
|
|
|
|
|
2015-12-17 19:18:42 +05:30
|
|
|
events: {
|
|
|
|
|
'switchChange.bootstrapSwitch': 'onChange'
|
|
|
|
|
},
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
|
2015-12-17 19:18:42 +05:30
|
|
|
onChange: function () {
|
|
|
|
|
var model = this.model,
|
|
|
|
|
column = this.column,
|
|
|
|
|
val = this.formatter.toRaw(this.$input.prop('checked'), model);
|
|
|
|
|
|
|
|
|
|
// on bootstrap change we also need to change model's value
|
|
|
|
|
model.set(column.get("name"), val);
|
|
|
|
|
},
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
|
2015-12-17 19:18:42 +05:30
|
|
|
render: function () {
|
|
|
|
|
var col = _.defaults(this.column.toJSON(), this.defaults),
|
|
|
|
|
attributes = this.model.toJSON(),
|
|
|
|
|
attrArr = col.name.split('.'),
|
|
|
|
|
name = attrArr.shift(),
|
|
|
|
|
path = attrArr.join('.'),
|
|
|
|
|
model = this.model, column = this.column,
|
2016-04-04 15:36:28 +05:30
|
|
|
rawValue = this.formatter.fromRaw(
|
|
|
|
|
model.get(column.get("name")), model
|
|
|
|
|
),
|
2015-12-17 19:18:42 +05:30
|
|
|
editable = Backgrid.callByNeed(col.editable, column, model);
|
|
|
|
|
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
this.undelegateEvents();
|
|
|
|
|
|
2015-12-17 19:18:42 +05:30
|
|
|
this.$el.empty();
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
|
2015-12-17 19:18:42 +05:30
|
|
|
this.$el.append(
|
|
|
|
|
$("<input>", {
|
|
|
|
|
tabIndex: -1,
|
|
|
|
|
type: "checkbox"
|
|
|
|
|
}).prop('checked', rawValue).prop('disabled', !editable));
|
|
|
|
|
this.$input = this.$el.find('input[type=checkbox]').first();
|
|
|
|
|
|
|
|
|
|
// Override BooleanCell checkbox with Bootstrapswitch
|
|
|
|
|
this.$input.bootstrapSwitch(
|
|
|
|
|
_.defaults(
|
2016-04-04 15:36:28 +05:30
|
|
|
{'state': rawValue, 'disabled': !editable}, col.options,
|
|
|
|
|
this.defaults.options
|
2015-12-17 19:18:42 +05:30
|
|
|
));
|
|
|
|
|
|
|
|
|
|
this.delegateEvents();
|
|
|
|
|
|
|
|
|
|
return this;
|
2015-12-04 15:49:08 +05:30
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-07 08:35:08 +05:30
|
|
|
/*
|
|
|
|
|
* Select2Cell for backgrid.
|
|
|
|
|
*/
|
2016-04-04 15:36:28 +05:30
|
|
|
var Select2Cell = Backgrid.Extension.Select2Cell =
|
|
|
|
|
Backgrid.SelectCell.extend({
|
2016-01-07 08:35:08 +05:30
|
|
|
className: "select2-cell",
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
|
2016-04-04 15:36:28 +05:30
|
|
|
/** @property */
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
editor: null,
|
|
|
|
|
|
2016-01-07 13:30:41 +05:30
|
|
|
defaults: _.defaults({
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
select2: {},
|
|
|
|
|
opt: {
|
2016-04-15 11:01:11 +05:30
|
|
|
label: null,
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
value: null,
|
|
|
|
|
selected: false
|
|
|
|
|
}
|
2016-04-04 15:36:28 +05:30
|
|
|
}, Backgrid.SelectCell.prototype.defaults),
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
|
|
|
|
|
enterEditMode: function() {
|
2016-04-15 11:01:11 +05:30
|
|
|
if (!this.$el.hasClass('editor'))
|
|
|
|
|
this.$el.addClass('editor');
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
this.$select.select2('focus');
|
2016-07-15 10:12:23 +01:00
|
|
|
this.$select.select2('open');
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
this.$select.on('blur', this.exitEditMode);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
exitEditMode: function() {
|
|
|
|
|
this.$select.off('blur', this.exitEditMode);
|
2016-07-15 10:12:23 +01:00
|
|
|
this.$select.select2('close');
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
this.$el.removeClass('editor');
|
|
|
|
|
},
|
|
|
|
|
|
2016-01-07 08:35:08 +05:30
|
|
|
events: {
|
2016-04-15 11:01:11 +05:30
|
|
|
"select2:open": "enterEditMode",
|
|
|
|
|
"select2:close": "exitEditMode",
|
2016-01-07 08:35:08 +05:30
|
|
|
"change": "onSave",
|
|
|
|
|
"select2:unselect": "onSave"
|
|
|
|
|
},
|
2016-04-04 15:36:28 +05:30
|
|
|
/** @property {function(Object, ?Object=): string} template */
|
|
|
|
|
template: _.template([
|
|
|
|
|
'<option value="<%- value %>" ',
|
|
|
|
|
'<%= selected ? \'selected="selected"\' : "" %>>',
|
2016-04-15 11:01:11 +05:30
|
|
|
'<%- label %></option>'].join(''),
|
2016-04-04 15:36:28 +05:30
|
|
|
null,{
|
|
|
|
|
variable: null
|
|
|
|
|
}),
|
|
|
|
|
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
initialize: function() {
|
|
|
|
|
Backgrid.SelectCell.prototype.initialize.apply(this, arguments);
|
|
|
|
|
this.onSave = this.onSave.bind(this);
|
2016-04-15 11:01:11 +05:30
|
|
|
this.enterEditMode = this.enterEditMode.bind(this);
|
|
|
|
|
this.exitEditMode = this.exitEditMode.bind(this);
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
},
|
|
|
|
|
|
2016-01-07 08:35:08 +05:30
|
|
|
render: function () {
|
|
|
|
|
var col = _.defaults(this.column.toJSON(), this.defaults),
|
|
|
|
|
model = this.model, column = this.column,
|
|
|
|
|
editable = Backgrid.callByNeed(col.editable, column, model),
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
optionValues = _.clone(this.optionValues ||
|
2016-06-03 15:20:54 +05:30
|
|
|
(_.isFunction(this.column.get('options')) ?
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
(this.column.get('options'))(this) :
|
2016-06-03 15:20:54 +05:30
|
|
|
this.column.get('options')));
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
|
|
|
|
|
this.undelegateEvents();
|
|
|
|
|
|
|
|
|
|
if (this.$select) {
|
2016-04-29 15:41:24 +05:30
|
|
|
if ( this.$select.data('select2')) {
|
|
|
|
|
this.$select.select2('destroy');
|
|
|
|
|
}
|
|
|
|
|
delete this.$select;
|
|
|
|
|
this.$select = null;
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
}
|
2016-01-07 08:35:08 +05:30
|
|
|
|
|
|
|
|
this.$el.empty();
|
|
|
|
|
|
2016-04-04 15:36:28 +05:30
|
|
|
if (!_.isArray(optionValues))
|
|
|
|
|
throw new TypeError("optionValues must be an array");
|
2016-01-07 08:35:08 +05:30
|
|
|
|
2016-01-07 13:30:41 +05:30
|
|
|
/*
|
|
|
|
|
* Add empty option as Select2 requires any empty '<option><option>' for
|
2016-01-07 08:35:08 +05:30
|
|
|
* some of its functionality to work.
|
|
|
|
|
*/
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
optionValues.unshift(this.defaults.opt);
|
2016-01-07 08:35:08 +05:30
|
|
|
|
|
|
|
|
var optionText = null,
|
|
|
|
|
optionValue = null,
|
2016-05-10 13:48:48 +05:30
|
|
|
self = this,
|
2016-01-07 08:35:08 +05:30
|
|
|
model = this.model,
|
2016-05-10 13:48:48 +05:30
|
|
|
selectedValues = model.get(this.column.get("name")),
|
|
|
|
|
select2_opts = _.extend(
|
|
|
|
|
{openOnEnter: false, multiple:false}, self.defaults.select2,
|
|
|
|
|
(col.select2 || {})
|
|
|
|
|
),
|
|
|
|
|
selectTpl = _.template('<select <%=multiple ? "multiple" : "" %>></select>');
|
2016-01-07 08:35:08 +05:30
|
|
|
|
2016-05-10 13:48:48 +05:30
|
|
|
$select = self.$select = $(selectTpl({
|
|
|
|
|
multiple: select2_opts.multiple
|
|
|
|
|
})).appendTo(self.$el);
|
2016-01-07 08:35:08 +05:30
|
|
|
|
|
|
|
|
for (var i = 0; i < optionValues.length; i++) {
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
var opt = optionValues[i];
|
|
|
|
|
|
|
|
|
|
if (_.isArray(opt)) {
|
2016-04-15 11:01:11 +05:30
|
|
|
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
optionText = opt[0];
|
|
|
|
|
optionValue = opt[1];
|
|
|
|
|
|
|
|
|
|
$select.append(
|
|
|
|
|
self.template({
|
2016-04-15 11:01:11 +05:30
|
|
|
label: optionText,
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
value: optionValue,
|
|
|
|
|
selected: (selectedValues == optionValue) ||
|
|
|
|
|
(_.indexOf(selectedValues, optionValue) > -1)
|
2016-01-07 08:35:08 +05:30
|
|
|
}));
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
} else {
|
2016-04-15 11:01:11 +05:30
|
|
|
opt = _.defaults({}, opt, {
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
selected: ((selectedValues == opt.value) ||
|
2016-04-15 11:01:11 +05:30
|
|
|
(_.indexOf(selectedValues, opt.value) > -1)),
|
|
|
|
|
}, self.defaults.opt);
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
$select.append(self.template(opt));
|
2016-01-07 08:35:08 +05:30
|
|
|
}
|
|
|
|
|
}
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
|
|
|
|
|
if(col && _.has(col.disabled)) {
|
|
|
|
|
_.extend(select2_opts, {
|
|
|
|
|
disabled: evalF(col.disabled, col, model)
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
_.extend(select2_opts, {disabled: !editable});
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 08:35:08 +05:30
|
|
|
this.delegateEvents();
|
|
|
|
|
|
2016-04-15 11:01:11 +05:30
|
|
|
// Initialize select2 control.
|
|
|
|
|
this.$select.select2(select2_opts);
|
|
|
|
|
|
2016-01-07 08:35:08 +05:30
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Saves the value of the selected option to the model attribute.
|
|
|
|
|
*/
|
|
|
|
|
onSave: function (e) {
|
|
|
|
|
var model = this.model;
|
|
|
|
|
var column = this.column;
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
|
2016-01-15 19:10:29 +05:30
|
|
|
model.set(column.get("name"), this.$select.val());
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
|
|
remove: function() {
|
|
|
|
|
this.$select.off('change', this.onSave);
|
2016-04-29 15:41:24 +05:30
|
|
|
if (this.$select.data('select2')) {
|
|
|
|
|
this.$select.select2('destroy');
|
|
|
|
|
}
|
Improvised Select2Cell, and SwitchCell.
Removed the use of separate editor for both of these cell types. There
were two instance of select2 were getting created in the Select2Cell,
one in the Select2Cell itself, and another in Select2CellEditor. And,
loosing the focus mysteriously, and making the scrollbar in the property
dialog non-responsive.
Also, modified the NodeAjaxOptionsCell to use the above logic, and
removed its own version of render function to make it consitent across
the system.
This patch [changes sent by Murtuza] also includes improvisation in the
DeleteCell, and ObjectCell, which will honour now 'canRemoveRow', and
''canEditRow' respective properties of Column.
2016-04-12 16:50:43 +05:30
|
|
|
this.$el.empty();
|
|
|
|
|
Backgrid.SelectCell.prototype.remove.apply(this, arguments);
|
2016-07-15 10:12:23 +01:00
|
|
|
}
|
2016-01-07 08:35:08 +05:30
|
|
|
});
|
2016-03-16 14:48:09 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
TextareaCellEditor the cell editor renders a textarea multi-line text input
|
|
|
|
|
box as its editor.
|
|
|
|
|
|
|
|
|
|
@class Backgrid.TextareaCellEditor
|
|
|
|
|
@extends Backgrid.InputCellEditor
|
|
|
|
|
*/
|
|
|
|
|
var TextareaCellEditor = Backgrid.TextareaCellEditor = Backgrid.InputCellEditor.extend({
|
|
|
|
|
/** @property */
|
|
|
|
|
tagName: "textarea",
|
|
|
|
|
|
|
|
|
|
events: {
|
|
|
|
|
"blur": "saveOrCancel",
|
|
|
|
|
"keydown": ""
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
TextareaCell displays multiline HTML strings.
|
|
|
|
|
|
|
|
|
|
@class Backgrid.Extension.TextareaCell
|
|
|
|
|
@extends Backgrid.Cell
|
|
|
|
|
*/
|
|
|
|
|
var TextareaCell = Backgrid.Extension.TextareaCell = Backgrid.Cell.extend({
|
|
|
|
|
/** @property */
|
|
|
|
|
className: "textarea-cell",
|
|
|
|
|
|
|
|
|
|
editor: TextareaCellEditor
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-14 21:36:04 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Custom header icon cell to add the icon in table header.
|
|
|
|
|
*/
|
|
|
|
|
var CustomHeaderIconCell = Backgrid.Extension.CustomHeaderIconCell = Backgrid.HeaderCell.extend({
|
|
|
|
|
/** @property */
|
|
|
|
|
className: "header-icon-cell",
|
|
|
|
|
events: {
|
|
|
|
|
"click": "addHeaderIcon"
|
|
|
|
|
},
|
|
|
|
|
addHeaderIcon: function (e) {
|
|
|
|
|
self = this;
|
|
|
|
|
m = new (this.collection.model);
|
|
|
|
|
this.collection.add(m)
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
},
|
|
|
|
|
render: function () {
|
|
|
|
|
this.$el.empty();
|
|
|
|
|
//this.$el.html("<i class='fa fa-plus-circle'></i>");
|
2016-07-21 17:18:15 +01:00
|
|
|
this.$el.html("<label><a><span style='font-weight:normal;'>Array Values</a></span></label> <button class='btn-sm btn-default add'>Add</button>");
|
2016-04-14 21:36:04 +01:00
|
|
|
this.delegateEvents();
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var arrayCellModel = Backbone.Model.extend({
|
|
|
|
|
defaults: {
|
|
|
|
|
value: undefined
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Custom InputArrayCellEditor for editing user input array for debugger.
|
|
|
|
|
*/
|
|
|
|
|
var InputArrayCellEditor = Backgrid.Extension.InputArrayCellEditor =
|
|
|
|
|
Backgrid.CellEditor.extend({
|
|
|
|
|
tagName: "div",
|
|
|
|
|
|
|
|
|
|
events: {
|
|
|
|
|
'blur': 'lostFocus'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
render: function () {
|
|
|
|
|
var self = this,
|
|
|
|
|
arrayValuesCol = this.model.get(this.column.get("name")),
|
|
|
|
|
tbl = $("<table></table>").appendTo(this.$el),
|
|
|
|
|
gridCols = [
|
|
|
|
|
{name: 'value', label:'Array Values', type: 'text', cell:'string', headerCell: Backgrid.Extension.CustomHeaderIconCell, cellHeaderClasses: 'width_percent_100'},
|
|
|
|
|
],
|
|
|
|
|
gridBody = $("<div class='pgadmin-control-group backgrid form-group col-xs-12 object subnode'></div>");
|
|
|
|
|
|
|
|
|
|
this.$el.attr('tabindex', '1');
|
|
|
|
|
|
|
|
|
|
gridCols.unshift({
|
|
|
|
|
name: "pg-backform-delete", label: "",
|
|
|
|
|
cell: Backgrid.Extension.DeleteCell,
|
|
|
|
|
//headerCell: Backgrid.Extension.CustomHeaderIconCell,
|
|
|
|
|
editable: false, cell_priority: -1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.$el.empty();
|
|
|
|
|
var grid = self.grid = new Backgrid.Grid({
|
|
|
|
|
columns: gridCols,
|
|
|
|
|
collection:arrayValuesCol
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
grid.render();
|
|
|
|
|
|
|
|
|
|
gridBody.append(grid.$el)
|
|
|
|
|
|
|
|
|
|
this.$el.html(gridBody);
|
|
|
|
|
|
|
|
|
|
$(self.$el).pgMakeVisible('backform-tab');
|
|
|
|
|
self.delegateEvents();
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Call back function when the grid lost the focus
|
|
|
|
|
*/
|
|
|
|
|
lostFocus: function(ev) {
|
|
|
|
|
|
|
|
|
|
var self = this,
|
|
|
|
|
/*
|
|
|
|
|
* Function to determine whether one dom element is descendant of another
|
|
|
|
|
* dom element.
|
|
|
|
|
*/
|
|
|
|
|
isDescendant = function (parent, child) {
|
|
|
|
|
var node = child.parentNode;
|
|
|
|
|
while (node != null) {
|
|
|
|
|
if (node == parent) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
node = node.parentNode;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Between leaving the old element focus and entering the new element focus the
|
|
|
|
|
* active element is the document/body itself so add timeout to get the proper
|
|
|
|
|
* focused active element.
|
|
|
|
|
*/
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
if (self.$el[0] != document.activeElement && !isDescendant(self.$el[0], document.activeElement)){
|
|
|
|
|
var m = self.model,
|
|
|
|
|
column = self.column;
|
|
|
|
|
m.trigger('backgrid:edited', m, column, new Backgrid.Command(ev));
|
|
|
|
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
|
if (self.grid) {
|
|
|
|
|
self.grid.remove();
|
|
|
|
|
self.grid = null;
|
|
|
|
|
}
|
|
|
|
|
}, 10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}},10);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This will help us transform the user input string array values in proper format to be
|
|
|
|
|
* displayed in the cell.
|
|
|
|
|
*/
|
|
|
|
|
var InputStringArrayCellFormatter = Backgrid.Extension.InputStringArrayCellFormatter =
|
|
|
|
|
function () {};
|
|
|
|
|
_.extend(InputStringArrayCellFormatter.prototype, {
|
|
|
|
|
/**
|
|
|
|
|
* Takes a raw value from a model and returns an optionally formatted
|
|
|
|
|
* string for display.
|
|
|
|
|
*/
|
|
|
|
|
fromRaw: function (rawData, model) {
|
|
|
|
|
var values = []
|
|
|
|
|
rawData.each(function(m){
|
|
|
|
|
var val = m.get('value');
|
|
|
|
|
if (_.isUndefined(val)) {
|
|
|
|
|
values.push("null");
|
|
|
|
|
} else {
|
|
|
|
|
values.push(m.get("value"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return values.toString();
|
|
|
|
|
},
|
|
|
|
|
toRaw: function (formattedData, model) {
|
|
|
|
|
return formattedData;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This will help us transform the user input integer array values in proper format to be
|
|
|
|
|
* displayed in the cell.
|
|
|
|
|
*/
|
|
|
|
|
var InputIntegerArrayCellFormatter = Backgrid.Extension.InputIntegerArrayCellFormatter =
|
|
|
|
|
function () {};
|
|
|
|
|
_.extend(InputIntegerArrayCellFormatter.prototype, {
|
|
|
|
|
/**
|
|
|
|
|
* Takes a raw value from a model and returns an optionally formatted
|
|
|
|
|
* string for display.
|
|
|
|
|
*/
|
|
|
|
|
fromRaw: function (rawData, model) {
|
|
|
|
|
var values = []
|
|
|
|
|
rawData.each(function(m){
|
|
|
|
|
var val = m.get('value');
|
|
|
|
|
if (_.isUndefined(val)) {
|
|
|
|
|
values.push("null");
|
|
|
|
|
} else {
|
|
|
|
|
values.push(m.get("value"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return values.toString();
|
|
|
|
|
},
|
|
|
|
|
toRaw: function (formattedData, model) {
|
|
|
|
|
formattedData.each(function(m){
|
|
|
|
|
m.set("value", parseInt(m.get('value')), {silent: true});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return formattedData;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* InputStringArrayCell for rendering and taking input for string array type in debugger
|
|
|
|
|
*/
|
|
|
|
|
var InputStringArrayCell = Backgrid.Extension.InputStringArrayCell = Backgrid.Cell.extend({
|
|
|
|
|
className: "width_percent_25",
|
|
|
|
|
formatter: InputStringArrayCellFormatter,
|
|
|
|
|
editor: InputArrayCellEditor,
|
|
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
|
Backgrid.Cell.prototype.initialize.apply(this, arguments);
|
|
|
|
|
// set value to empty array.
|
2016-05-06 16:02:11 +05:30
|
|
|
var m = arguments[0].model;
|
2016-04-14 21:36:04 +01:00
|
|
|
if (_.isUndefined(this.collection)) {
|
|
|
|
|
this.collection = new (Backbone.Collection.extend({
|
2016-05-06 16:02:11 +05:30
|
|
|
model: arrayCellModel}))(m.get('value'));
|
2016-04-14 21:36:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.model.set(this.column.get('name'), this.collection);
|
|
|
|
|
|
|
|
|
|
this.listenTo(this.collection, "remove", this.render);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* InputIntegerArrayCell for rendering and taking input for integer array type in debugger
|
|
|
|
|
*/
|
|
|
|
|
var InputIntegerArrayCell = Backgrid.Extension.InputIntegerArrayCell = Backgrid.Cell.extend({
|
|
|
|
|
className: "width_percent_25",
|
|
|
|
|
formatter: InputIntegerArrayCellFormatter,
|
|
|
|
|
editor: InputArrayCellEditor,
|
|
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
|
Backgrid.Cell.prototype.initialize.apply(this, arguments);
|
|
|
|
|
// set value to empty array.
|
2016-05-06 16:02:11 +05:30
|
|
|
var m = arguments[0].model;
|
2016-04-14 21:36:04 +01:00
|
|
|
if (_.isUndefined(this.collection)) {
|
|
|
|
|
this.collection = new (Backbone.Collection.extend({
|
2016-05-06 16:02:11 +05:30
|
|
|
model: arrayCellModel}))(m.get('value'));
|
2016-04-14 21:36:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.model.set(this.column.get('name'),this.collection);
|
|
|
|
|
|
|
|
|
|
this.listenTo(this.collection, "remove", this.render);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2016-05-10 12:40:39 +05:30
|
|
|
/**
|
|
|
|
|
* DependentCell functions can be used with the different cell type in order
|
|
|
|
|
* to setup the callback for the depedent attribute change in the model.
|
|
|
|
|
*
|
|
|
|
|
* Please implement the 'dependentChanged' as the callback in the used cell.
|
|
|
|
|
*
|
|
|
|
|
* @class Backgrid.Extension.DependentCell
|
|
|
|
|
**/
|
|
|
|
|
var DependentCell = Backgrid.Extension.DependentCell = function() {};
|
|
|
|
|
|
|
|
|
|
_.extend(
|
|
|
|
|
DependentCell.prototype, {
|
|
|
|
|
initialize: function(){
|
|
|
|
|
// Listen to the dependent fields in the model for any change
|
|
|
|
|
var deps = this.column.get('deps');
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
if (deps && _.isArray(deps)) {
|
|
|
|
|
_.each(deps, function(d) {
|
|
|
|
|
attrArr = d.split('.');
|
|
|
|
|
name = attrArr.shift();
|
|
|
|
|
self.listenTo(self.model, "change:" + name, self.dependentChanged);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
remove: function() {
|
|
|
|
|
// Remove the events for the dependent fields in the model
|
|
|
|
|
var self = this,
|
|
|
|
|
deps = self.column.get('deps');
|
|
|
|
|
|
|
|
|
|
if (deps && _.isArray(deps)) {
|
|
|
|
|
_.each(deps, function(d) {
|
|
|
|
|
attrArr = d.split('.');
|
|
|
|
|
name = attrArr.shift();
|
|
|
|
|
|
|
|
|
|
self.stopListening(self.model, "change:" + name, self.dependentChanged);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-03 16:13:42 +05:30
|
|
|
/**
|
|
|
|
|
Formatter for PasswordCell.
|
|
|
|
|
|
|
|
|
|
@class Backgrid.PasswordFormatter
|
|
|
|
|
@extends Backgrid.CellFormatter
|
|
|
|
|
@constructor
|
|
|
|
|
*/
|
|
|
|
|
var PasswordFormatter = Backgrid.PasswordFormatter = function () {};
|
|
|
|
|
PasswordFormatter.prototype = new Backgrid.CellFormatter();
|
|
|
|
|
_.extend(PasswordFormatter.prototype, {
|
|
|
|
|
fromRaw: function (rawValue, model) {
|
|
|
|
|
|
|
|
|
|
if (_.isUndefined(rawValue) || _.isNull(rawValue)) return '';
|
|
|
|
|
|
|
|
|
|
var pass = '';
|
|
|
|
|
for(var i = 0; i < rawValue.length; i++) {
|
|
|
|
|
pass += '*';
|
|
|
|
|
}
|
|
|
|
|
return pass;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var PasswordCell = Backgrid.Extension.PasswordCell = Backgrid.StringCell.extend({
|
|
|
|
|
|
|
|
|
|
formatter: PasswordFormatter,
|
|
|
|
|
|
|
|
|
|
editor: Backgrid.InputCellEditor.extend({
|
|
|
|
|
attributes: {
|
|
|
|
|
type: "password"
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
render: function () {
|
|
|
|
|
var model = this.model;
|
|
|
|
|
this.$el.val(model.get(this.column.get("name")));
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-23 12:46:48 +01:00
|
|
|
/*
|
|
|
|
|
* Override NumberFormatter to support NaN, Infinity values.
|
|
|
|
|
* On client side, JSON do not directly support NaN & Infinity,
|
|
|
|
|
* we explicitly converted it into string format at server side
|
|
|
|
|
* and we need to parse it again in float at client side.
|
|
|
|
|
*/
|
|
|
|
|
_.extend(Backgrid.NumberFormatter.prototype, {
|
|
|
|
|
fromRaw: function (number, model) {
|
|
|
|
|
if (_.isNull(number) || _.isUndefined(number)) return '';
|
|
|
|
|
|
|
|
|
|
number = parseFloat(number).toFixed(~~this.decimals);
|
|
|
|
|
|
|
|
|
|
var parts = number.split('.');
|
|
|
|
|
var integerPart = parts[0];
|
|
|
|
|
var decimalPart = parts[1] ? (this.decimalSeparator || '.') + parts[1] : '';
|
|
|
|
|
|
|
|
|
|
return integerPart.replace(this.HUMANIZED_NUM_RE, '$1' + this.orderSeparator) + decimalPart;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-07-04 10:05:59 +01:00
|
|
|
/*
|
|
|
|
|
* JSONBCell Formatter.
|
|
|
|
|
*/
|
|
|
|
|
var JSONBCellFormatter = Backgrid.Extension.JSONBCellFormatter =
|
|
|
|
|
function () {};
|
|
|
|
|
_.extend(JSONBCellFormatter.prototype, {
|
|
|
|
|
fromRaw: function (rawData, model) {
|
|
|
|
|
// json data
|
|
|
|
|
if(_.isArray(rawData)) {
|
|
|
|
|
var converted_data = '';
|
|
|
|
|
converted_data = _.map(rawData, function(data) {
|
|
|
|
|
return JSON.stringify(JSON.stringify(data));
|
|
|
|
|
});
|
|
|
|
|
return '{' + converted_data.join() + '}';
|
|
|
|
|
} else if(_.isObject(rawData)) {
|
|
|
|
|
return JSON.stringify(rawData);
|
|
|
|
|
} else {
|
|
|
|
|
return rawData;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
toRaw: function (formattedData, model) {
|
|
|
|
|
return formattedData;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* JSONBCell for backgrid.
|
|
|
|
|
*/
|
|
|
|
|
var JSONBCell = Backgrid.Extension.JSONBCell =
|
|
|
|
|
Backgrid.StringCell.extend({
|
|
|
|
|
className: "jsonb-cell",
|
|
|
|
|
formatter: JSONBCellFormatter
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-28 22:36:09 +05:30
|
|
|
return Backgrid;
|
|
|
|
|
|
|
|
|
|
}));
|