[view/slickgrid][s]: tidy up e.g. whitespace (no substance to change).
This commit is contained in:
@@ -5,37 +5,7 @@ this.recline.View = this.recline.View || {};
|
|||||||
|
|
||||||
(function($, my) {
|
(function($, my) {
|
||||||
"use strict";
|
"use strict";
|
||||||
// Add new grid Control to display a new row add menu bouton
|
|
||||||
// It display a simple side-bar menu ,for user to add new
|
|
||||||
// row to grid
|
|
||||||
|
|
||||||
my.GridControl= Backbone.View.extend({
|
|
||||||
className: "recline-row-add",
|
|
||||||
// Template for row edit menu , change it if you don't love
|
|
||||||
template: '<h1><a href="#" class="recline-row-add btn">Add row</a></h1>',
|
|
||||||
|
|
||||||
initialize: function(options){
|
|
||||||
var self = this;
|
|
||||||
_.bindAll(this, 'render');
|
|
||||||
this.state = new recline.Model.ObjectState();
|
|
||||||
this.render();
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function() {
|
|
||||||
var self = this;
|
|
||||||
this.$el.html(this.template)
|
|
||||||
},
|
|
||||||
|
|
||||||
events : {
|
|
||||||
"click .recline-row-add" : "addNewRow"
|
|
||||||
},
|
|
||||||
|
|
||||||
addNewRow : function(e){
|
|
||||||
e.preventDefault()
|
|
||||||
this.state.trigger("change")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
// ## SlickGrid Dataset View
|
// ## SlickGrid Dataset View
|
||||||
//
|
//
|
||||||
// Provides a tabular view on a Dataset, based on SlickGrid.
|
// Provides a tabular view on a Dataset, based on SlickGrid.
|
||||||
@@ -56,7 +26,11 @@ this.recline.View = this.recline.View || {};
|
|||||||
// state: {
|
// state: {
|
||||||
// gridOptions: {
|
// gridOptions: {
|
||||||
// editable: true,
|
// editable: true,
|
||||||
// enableAddRows: true
|
// enableAddRow: true
|
||||||
|
// // Enable support for row delete
|
||||||
|
// enabledDelRow: true,
|
||||||
|
// // Enable support for row Reorder
|
||||||
|
// enableReOrderRow:true,
|
||||||
// ...
|
// ...
|
||||||
// },
|
// },
|
||||||
// columnsEditor: [
|
// columnsEditor: [
|
||||||
@@ -104,6 +78,7 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onRecordChanged: function(record) {
|
onRecordChanged: function(record) {
|
||||||
// Ignore if the grid is not yet drawn
|
// Ignore if the grid is not yet drawn
|
||||||
if (!this.grid) {
|
if (!this.grid) {
|
||||||
@@ -115,6 +90,7 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
this.grid.getData().updateItem(record, row_index);
|
this.grid.getData().updateItem(record, row_index);
|
||||||
this.grid.render();
|
this.grid.render();
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var options = _.extend({
|
var options = _.extend({
|
||||||
@@ -127,6 +103,7 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
|
|
||||||
// We need all columns, even the hidden ones, to show on the column picker
|
// We need all columns, even the hidden ones, to show on the column picker
|
||||||
var columns = [];
|
var columns = [];
|
||||||
|
|
||||||
// custom formatter as default one escapes html
|
// custom formatter as default one escapes html
|
||||||
// plus this way we distinguish between rendering/formatting and computed value (so e.g. sort still works ...)
|
// plus this way we distinguish between rendering/formatting and computed value (so e.g. sort still works ...)
|
||||||
// row = row index, cell = cell index, value = value, columnDef = column definition, dataContext = full row values
|
// row = row index, cell = cell index, value = value, columnDef = column definition, dataContext = full row values
|
||||||
@@ -137,33 +114,29 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
var field = self.model.fields.get(columnDef.id);
|
var field = self.model.fields.get(columnDef.id);
|
||||||
if (field.renderer) {
|
if (field.renderer) {
|
||||||
return field.renderer(value, field, dataContext);
|
return field.renderer(value, field, dataContext);
|
||||||
}else {
|
} else {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// we need to be sure that user is entering a valid input , for exemple if
|
// we need to be sure that user is entering a valid input , for exemple if
|
||||||
// field is date type and field.format ='YY-MM-DD', we should be sure that
|
// field is date type and field.format ='YY-MM-DD', we should be sure that
|
||||||
// user enter a correct value
|
// user enter a correct value
|
||||||
var validator = function(field){
|
var validator = function(field) {
|
||||||
return function(value){
|
return function(value){
|
||||||
if(field.type == "date" && isNaN(Date.parse(value))){
|
if (field.type == "date" && isNaN(Date.parse(value))){
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
msg: "A date is required, check field field-date-format"};
|
msg: "A date is required, check field field-date-format"
|
||||||
}else {
|
};
|
||||||
|
} else {
|
||||||
return {valid: true, msg :null }
|
return {valid: true, msg :null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//Add row delete support, check if enableReOrderRow is set to true , by
|
|
||||||
//default it is set to false
|
// Add column for row reorder support
|
||||||
// state: {
|
if (this.state.get("gridOptions") && this.state.get("gridOptions").enableReOrderRow == true) {
|
||||||
// gridOptions: {
|
|
||||||
// enableReOrderRow: true,
|
|
||||||
// },
|
|
||||||
if(this.state.get("gridOptions")
|
|
||||||
&& this.state.get("gridOptions").enableReOrderRow != undefined
|
|
||||||
&& this.state.get("gridOptions").enableReOrderRow == true ){
|
|
||||||
columns.push({
|
columns.push({
|
||||||
id: "#",
|
id: "#",
|
||||||
name: "",
|
name: "",
|
||||||
@@ -174,15 +147,8 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
cssClass: "recline-cell-reorder"
|
cssClass: "recline-cell-reorder"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
//Add row delete support, check if enabledDelRow is set to true , by
|
// Add column for row delete support
|
||||||
//default it is set to false
|
if (this.state.get("gridOptions") && this.state.get("gridOptions").enabledDelRow == true) {
|
||||||
// state: {
|
|
||||||
// gridOptions: {
|
|
||||||
// enabledDelRow: true,
|
|
||||||
// },
|
|
||||||
if(this.state.get("gridOptions")
|
|
||||||
&& this.state.get("gridOptions").enabledDelRow != undefined
|
|
||||||
&& this.state.get("gridOptions").enabledDelRow == true ){
|
|
||||||
columns.push({
|
columns.push({
|
||||||
id: 'del',
|
id: 'del',
|
||||||
name: '',
|
name: '',
|
||||||
@@ -193,6 +159,7 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
validator:validator
|
validator:validator
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_.each(this.model.fields.toJSON(),function(field){
|
_.each(this.model.fields.toJSON(),function(field){
|
||||||
var column = {
|
var column = {
|
||||||
id: field.id,
|
id: field.id,
|
||||||
@@ -254,10 +221,11 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
columns = columns.concat(tempHiddenColumns);
|
columns = columns.concat(tempHiddenColumns);
|
||||||
|
|
||||||
// Transform a model object into a row
|
// Transform a model object into a row
|
||||||
function toRow(m) {
|
function toRow(m) {
|
||||||
var row = {};
|
var row = {};
|
||||||
self.model.fields.each(function(field){
|
self.model.fields.each(function(field) {
|
||||||
var render = "";
|
var render = "";
|
||||||
//when adding row from slickgrid the field value is undefined
|
//when adding row from slickgrid the field value is undefined
|
||||||
if(!_.isUndefined(m.getFieldValueUnrendered(field))){
|
if(!_.isUndefined(m.getFieldValueUnrendered(field))){
|
||||||
@@ -304,7 +272,6 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
this.grid.setSortColumn(column, sortAsc);
|
this.grid.setSortColumn(column, sortAsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Row reordering support based on
|
/* Row reordering support based on
|
||||||
https://github.com/mleibman/SlickGrid/blob/gh-pages/examples/example9-row-reordering.html
|
https://github.com/mleibman/SlickGrid/blob/gh-pages/examples/example9-row-reordering.html
|
||||||
|
|
||||||
@@ -362,9 +329,7 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
|
|
||||||
});
|
});
|
||||||
//register The plugin to handle row Reorder
|
//register The plugin to handle row Reorder
|
||||||
if(this.state.get("gridOptions")
|
if(this.state.get("gridOptions") && this.state.get("gridOptions").enableReOrderRow) {
|
||||||
&& this.state.get("gridOptions").enableReOrderRow != undefined
|
|
||||||
&& this.state.get("gridOptions").enableReOrderRow == true ){
|
|
||||||
self.grid.registerPlugin(moveRowsPlugin);
|
self.grid.registerPlugin(moveRowsPlugin);
|
||||||
}
|
}
|
||||||
/* end row reordering support*/
|
/* end row reordering support*/
|
||||||
@@ -434,7 +399,6 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
self.rendered = false;
|
self.rendered = false;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
remove: function () {
|
remove: function () {
|
||||||
@@ -460,6 +424,36 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add new grid Control to display a new row add menu bouton
|
||||||
|
// It display a simple side-bar menu ,for user to add new
|
||||||
|
// row to grid
|
||||||
|
my.GridControl= Backbone.View.extend({
|
||||||
|
className: "recline-row-add",
|
||||||
|
// Template for row edit menu , change it if you don't love
|
||||||
|
template: '<h1><a href="#" class="recline-row-add btn">Add row</a></h1>',
|
||||||
|
|
||||||
|
initialize: function(options){
|
||||||
|
var self = this;
|
||||||
|
_.bindAll(this, 'render');
|
||||||
|
this.state = new recline.Model.ObjectState();
|
||||||
|
this.render();
|
||||||
|
},
|
||||||
|
|
||||||
|
render: function() {
|
||||||
|
var self = this;
|
||||||
|
this.$el.html(this.template)
|
||||||
|
},
|
||||||
|
|
||||||
|
events : {
|
||||||
|
"click .recline-row-add" : "addNewRow"
|
||||||
|
},
|
||||||
|
|
||||||
|
addNewRow : function(e){
|
||||||
|
e.preventDefault()
|
||||||
|
this.state.trigger("change")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
})(jQuery, recline.View);
|
})(jQuery, recline.View);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -578,6 +572,13 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slick.Controls.ColumnPicker
|
// Slick.Controls.ColumnPicker
|
||||||
$.extend(true, window, { Slick:{ Controls:{ ColumnPicker:SlickColumnPicker }}});
|
$.extend(true, window, {
|
||||||
|
Slick: {
|
||||||
|
Controls: {
|
||||||
|
ColumnPicker: SlickColumnPicker
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user