Commit 89240382 authored by Malcolm Blaney's avatar Malcolm Blaney

Stock module rewrite for inline grid editing. Refactored column

editing code from Members module to generic version in the Grid
module. This is now also used by the Stock module. New SupplierOnly
function in Detail module which is used to create a supplier select
which is used when importing supplier lists in the Stock module.
parent 6e9ea53a
Pipeline #11482353 passed with stage
in 2 minutes and 10 seconds
......@@ -16,6 +16,7 @@ php/modules/Indieauth.php
php/modules/Invite.php
php/modules/Invoice.php
php/modules/Manager.php
php/modules/Members.php
php/modules/Pager.php
php/modules/Payment.php
php/modules/Player.php
......@@ -35,6 +36,7 @@ php/modules/Start.php
php/modules/Stock.php
php/modules/Summary.php
php/modules/Turner.php
php/modules/Usb.php
php/modules/Viewanalytics.php
php/modules/Workgroup.php
php/modules/Writer.php
......@@ -56,6 +58,7 @@ js/dobrado.indieauth.js
js/dobrado.invite.js
js/dobrado.invoice.js
js/dobrado.manager.js
js/dobrado.members.js
js/dobrado.pager.js
js/dobrado.payment.js
js/dobrado.player.js
......@@ -75,6 +78,7 @@ js/dobrado.start.js
js/dobrado.stock.js
js/dobrado.summary.js
js/dobrado.turner.js
js/dobrado.usb.js
js/dobrado.viewanalytics.js
js/dobrado.writer.js
js/dobrado.xero.js
......@@ -95,6 +99,7 @@ js/source/dobrado.indieauth.js
js/source/dobrado.invite.js
js/source/dobrado.invoice.js
js/source/dobrado.manager.js
js/source/dobrado.members.js
js/source/dobrado.pager.js
js/source/dobrado.payment.js
js/source/dobrado.player.js
......@@ -114,6 +119,7 @@ js/source/dobrado.start.js
js/source/dobrado.stock.js
js/source/dobrado.summary.js
js/source/dobrado.turner.js
js/source/dobrado.usb.js
js/source/dobrado.viewanalytics.js
js/source/dobrado.writer.js
js/source/dobrado.xero.js
......
......@@ -557,6 +557,36 @@ class Detail extends Base {
return $reminder_time < time() + (86400 * 14);
}
public function SupplierOnly() {
$suppliers = [];
$organiser = new Organiser($this->user, $this->owner);
$query = 'SELECT users.user, first, last FROM users LEFT JOIN user_detail '.
'ON users.user = user_detail.user WHERE supplier_only = 1 AND '.
$organiser->GroupQuery();
$mysqli = connect_db();
if ($result = $mysqli->query($query)) {
while ($user_detail = $result->fetch_assoc()) {
$user = $user_detail['user'];
$name = $user_detail['first'];
$last = $user_detail['last'];
if ($name === '') {
$name = $user;
}
else if ($last !== '') {
$name .= ' '.$last;
}
$suppliers[$user] = $name;
}
$result->close();
}
else {
$this->Log('Detail->SupplierOnly: '.$mysqli->error);
}
$mysqli->close();
return $suppliers;
}
public function UpdateField($user, $field, $value) {
$mysqli = connect_db();
$query = 'UPDATE user_detail SET '.$field.' = "'.$value.'" WHERE '.
......
......@@ -83,7 +83,9 @@ class Grid extends Base {
'"",".slick-cell.selected","background-color","#f0f0f0"',
'"",".slick-cell > input[type=text]","border","none"',
'"",".slick-cell > input[type=text]","width","100%"',
'"",".slick-cell > input[type=text]","height","100%"'];
'"",".slick-cell > input[type=text]","height","100%"',
'"","button.long-text-save","float","right"',
'"","button.long-text-save","margin-left","10px"'];
$this->AddSiteStyle($site_style);
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -86,6 +86,111 @@ if (!this.dobrado.grid) {
}
}
dobrado.grid.showColumns = (function() {
// The total width of all column options to calculate display.
var totalColumnWidth = 0;
var columnDisplayWidth = 0;
// The column display width is reduced by the width of the two control
// buttons to produce the final display area width.
var buttonWidth = 78;
var scrollAmount = 0;
// Store the initial width of the parent container for the grid.
var initialWidth = 0;
var wideGrid = false;
function showColumnOptions(module) {
// Modules that want to use this feature should create this html:
var display = '#' + module + '-column-display';
var wrapper = '#' + module + '-column-wrapper';
var columns = '#' + module + '-columns';
$(display).toggle();
// Calculate the total column width the first time the options are shown.
if (totalColumnWidth === 0) {
$(columns + ' > label').each(function() {
totalColumnWidth += $(this).outerWidth(true);
});
$(columns).width(totalColumnWidth);
}
columnDisplayWidth = $(display).width();
$(wrapper).width(columnDisplayWidth - buttonWidth);
// The scroll amount is reduced so that the final button displayed
// doesn't get obscured on both sides of the viewing area.
scrollAmount = columnDisplayWidth - 150;
}
function showColumnsLeft(module) {
var columns = '#' + module + '-columns';
var left = parseInt($(columns).css('margin-left'), 10) + scrollAmount;
if (left >= 0) {
left = 0;
$('#' + module + '-column-left').button({ disabled: true });
}
$('#' + module + '-column-right').button({ disabled: false });
$(columns).css('margin-left', left + 'px');
}
function showColumnsRight(module) {
var columns = '#' + module + '-columns';
var left = parseInt($(columns).css('margin-left'), 10) - scrollAmount;
// The extra amount here is for the left and right buttons.
if (left <= columnDisplayWidth - totalColumnWidth - buttonWidth) {
left = columnDisplayWidth - totalColumnWidth - buttonWidth;
$('#' + module + '-column-right').button({ disabled: true });
}
$('#' + module + '-column-left').button({ disabled: false });
$(columns).css('margin-left', left + 'px');
}
function toggleWideGrid(module, grid) {
// Make sure the module is in the middle section of the layout,
// and then store the initial width so that it can be toggled.
if (initialWidth === 0) {
initialWidth = $('.' + module).parents('.middle').width();
}
if (initialWidth) {
wideGrid = !wideGrid;
if (dobrado.localStorage) {
localStorage[module + 'WideGrid'] = JSON.stringify(wideGrid);
}
if (wideGrid) {
$('.middle').width('99%');
}
else {
$('.middle').width(initialWidth);
}
if (grid) {
grid.resizeCanvas();
}
// Also re-calculate the column options display width.
var display = '#' + module + '-column-display';
var wrapper = '#' + module + '-column-wrapper';
columnDisplayWidth = $(display).width();
$(wrapper).width(columnDisplayWidth - buttonWidth);
scrollAmount = columnDisplayWidth - 150;
// In wide mode the options may already be scrolled as far as possible
// to the right, so scroll back to the left.
if (wideGrid) {
showColumnsLeft(module);
}
}
}
return function(module, fn, grid) {
if (fn === 'options') {
showColumnOptions(module);
}
else if (fn === 'left') {
showColumnsLeft(module);
}
else if (fn === 'right') {
showColumnsRight(module);
}
else if (fn === 'wide') {
toggleWideGrid(module, grid);
}
};
}());
dobrado.grid.instance = function(id, rows, columns, options) {
if (!list[id]) {
list[id] = new Slick.Grid(id + ' .view', rows, columns, options);
......@@ -990,6 +1095,7 @@ if (!this.dobrado.grid) {
"Checkmark": CheckmarkFormatter,
"Timestamp": TimestampFormatter,
"Units" : Units,
"StockUnits" : StockUnits,
"Dollar" : Dollar,
"Quota" : Quota,
"Fullname" : Fullname
......@@ -1048,6 +1154,25 @@ if (!this.dobrado.grid) {
return '';
}
function StockUnits(row, cell, value, columnDef, dataContext) {
if (value) {
if (value === 'g') {
return 'grams';
}
if (value === 'L') {
return 'litre';
}
if (value === 'variable') {
return 'as marked';
}
if (value === 'adjusted') {
return 'random weight';
}
return value;
}
return '';
}
function Dollar(row, cell, value, columnDef, dataContext) {
if (value) {
return '$' + value;
......@@ -1115,6 +1240,7 @@ if (!this.dobrado.grid) {
"Date": DateEditor,
"YesNoSelect": YesNoSelectEditor,
"BuyerEditor" : BuyerEditor,
"StockUnits": UnitsEditor,
"MembershipEditor" : MembershipEditor,
"Checkbox": CheckboxEditor,
"PercentComplete": PercentCompleteEditor,
......@@ -1506,7 +1632,7 @@ if (!this.dobrado.grid) {
this.init = function () {
$select = $("<SELECT tabIndex='0' class='editor-buyer'><OPTION value=''>Base Rate</OPTION><OPTION value='wholesale'>Wholesale</OPTION><OPTION value='retail'>Retail</OPTION></SELECT>");
$select.appendTo(args.container);
$select.focus();
$select.selectmenu({ width: null }).focus();
};
this.destroy = function () {
......@@ -1519,7 +1645,7 @@ if (!this.dobrado.grid) {
this.loadValue = function (item) {
$select.val((defaultValue = item[args.column.field]));
$select.select();
$select.selectmenu('refresh');
};
this.serializeValue = function () {
......@@ -1552,9 +1678,55 @@ if (!this.dobrado.grid) {
this.init = function () {
$select = $("<SELECT tabIndex='0' class='editor-membership'><OPTION>6 months</OPTION><OPTION>12 months</OPTION></SELECT>");
$select.appendTo(args.container);
$select.selectmenu({ width: null }).focus();
};
this.destroy = function () {
$select.remove();
};
this.focus = function () {
$select.focus();
};
this.loadValue = function (item) {
$select.val((defaultValue = item[args.column.field]));
$select.selectmenu('refresh');
};
this.serializeValue = function () {
return $select.val();
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return ($select.val() !== defaultValue);
};
this.validate = function () {
return {
valid: true,
msg: null
};
};
this.init();
}
function UnitsEditor(args) {
var $select;
var defaultValue;
var scope = this;
this.init = function () {
$select = $("<SELECT tabIndex='0' class='editor-units'><OPTION value='each'>each</OPTION><OPTION value='kg'>kg</OPTION><OPTION value='g'>grams</OPTION><OPTION value='L'>litre</OPTION><OPTION value='variable'>as marked</OPTION><OPTION value='adjusted'>random weight</OPTION></SELECT>");
$select.appendTo(args.container);
$select.selectmenu({ width: null }).focus();
};
this.destroy = function () {
$select.remove();
};
......@@ -1565,7 +1737,7 @@ if (!this.dobrado.grid) {
this.loadValue = function (item) {
$select.val((defaultValue = item[args.column.field]));
$select.select();
$select.selectmenu('refresh');
};
this.serializeValue = function () {
......@@ -1732,17 +1904,17 @@ if (!this.dobrado.grid) {
this.init = function () {
var $container = $("body");
$wrapper = $("<DIV style='z-index:10000;position:absolute;background:white;padding:5px;border:3px solid gray; -moz-border-radius:10px; border-radius:10px;'/>")
$wrapper = $("<DIV style='z-index:10000;position:absolute;background:white;width:200px;padding:5px;border:2px solid gray; -moz-border-radius:5px; border-radius:5px;'/>")
.appendTo($container);
$input = $("<TEXTAREA hidefocus rows=5 style='background:white;width:250px;height:80px;border:0;outline:0'>")
$input = $("<TEXTAREA hidefocus rows=5 style='background:white;width:100%;height:80px;border:0;outline:0'>")
.appendTo($wrapper);
$("<DIV style='text-align:right'><BUTTON>Save</BUTTON><BUTTON>Cancel</BUTTON></DIV>")
$('<DIV><BUTTON class="long-text-cancel">Cancel</BUTTON><BUTTON class="long-text-save">Save</BUTTON></DIV>')
.appendTo($wrapper);
$wrapper.find("button:first").on("click", this.save);
$wrapper.find("button:last").on("click", this.cancel);
$wrapper.find("button.long-text-save").button().click(this.save);
$wrapper.find("button.long-text-cancel").button().click(this.cancel);
$input.on("keydown", this.handleKeyDown);
scope.position(args.position);
......
......@@ -25,8 +25,8 @@
// for the JavaScript code in this page.
if(!this.dobrado.members){dobrado.members={};}
(function(){'use strict';var members={};var grid=null;var allColumns=[];var totalColumnWidth=0;var columnDisplayWidth=0;var buttonWidth=78;var scrollAmount=0;var initialWidth=0;var wideGrid=false;var supplierColumn=false;var activeColumn=false;$(function(){if($('.members').length===0){return;}
$('#members-show-columns').prop('checked',false).click(showColumnOptions);$('#members-columns > input').prop('checked',false);$('#members-wide-grid').prop('checked',false).click(toggleWideGrid);$('.members input[type=checkbox]').checkboxradio({icon:false});$('#members-download').button().click(download);$('#members-column-left').button({icon:'ui-icon-triangle-1-w',showLabel:false,disabled:true,}).click(showColumnsLeft);$('#members-column-right').button({icon:'ui-icon-triangle-1-e',showLabel:false,disabled:false,}).click(showColumnsRight);$('#members-columns').controlgroup().click(updateColumns);var columns=JSON.stringify(['username','first','last','email','phone']);var sort='';if(dobrado.localStorage){if(localStorage.membersColumns){columns=localStorage.membersColumns;}
(function(){'use strict';var members={};var grid=null;var allColumns=[];var supplierColumn=false;var activeColumn=false;$(function(){if($('.members').length===0){return;}
$('#members-columns > input').prop('checked',false);$('.members input[type=checkbox]').checkboxradio({icon:false});$('#members-download').button().click(download);$('#members-columns').controlgroup().click(updateColumns);$('#members-show-columns').prop('checked',false).click(function(){dobrado.grid.showColumns('members','options');});$('#members-column-left').button({icon:'ui-icon-triangle-1-w',showLabel:false,disabled:true}).click(function(){dobrado.grid.showColumns('members','left');});$('#members-column-right').button({icon:'ui-icon-triangle-1-e',showLabel:false,disabled:false}).click(function(){dobrado.grid.showColumns('members','right');});var columns=JSON.stringify(['username','first','last','email','phone']);var sort='';if(dobrado.localStorage){if(localStorage.membersColumns){columns=localStorage.membersColumns;}
if(localStorage.membersSortColumns){sort=localStorage.membersSortColumns;}}
dobrado.log('Loading members...','info');$.post('/php/request.php',{request:'members',action:'list',columns:columns,sort:sort,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'members list')){return;}
members=JSON.parse(response);if($('.grid').length!==0){gridSetup();}
......@@ -43,29 +43,15 @@ grid=dobrado.grid.instance(id,members.data,columns,options);grid.setSelectionMod
if(value1===value2){continue;}
if(value1>value2){return sign;}
else{return sign* -1;}}
return 0;});grid.invalidate();if(dobrado.localStorage){localStorage.membersSortColumns=JSON.stringify(grid.getSortColumns());}});if(dobrado.localStorage){if(localStorage.membersWideGrid==='true'){$('#members-wide-grid').click();}
return 0;});grid.invalidate();if(dobrado.localStorage){localStorage.membersSortColumns=JSON.stringify(grid.getSortColumns());}});$('#members-wide-grid').prop('checked',false).click(function(){dobrado.grid.showColumns('members','wide',grid);});if(dobrado.localStorage){if(localStorage.membersWideGrid==='true'){$('#members-wide-grid').click();}
if(localStorage.membersSortColumns){grid.setSortColumns(JSON.parse(localStorage.membersSortColumns));}}}
function showColumnOptions(){$('#members-column-display').toggle();if(totalColumnWidth===0){$('#members-columns > label').each(function(){totalColumnWidth+=$(this).outerWidth(true);});$('#members-columns').width(totalColumnWidth);}
columnDisplayWidth=$('#members-column-display').width();$('#members-column-wrapper').width(columnDisplayWidth-buttonWidth);scrollAmount=columnDisplayWidth-150;}
function showColumnsLeft(){var left=parseInt($('#members-columns').css('margin-left'),10)+
scrollAmount;if(left>=0){left=0;$('#members-column-left').button({disabled:true});}
$('#members-column-right').button({disabled:false});$('#members-columns').css('margin-left',left+'px');}
function showColumnsRight(){var left=parseInt($('#members-columns').css('margin-left'),10)-
scrollAmount;if(left<=columnDisplayWidth-totalColumnWidth-buttonWidth){left=columnDisplayWidth-totalColumnWidth-buttonWidth;$('#members-column-right').button({disabled:true});}
$('#members-column-left').button({disabled:false});$('#members-columns').css('margin-left',left+'px');}
function toggleWideGrid(){if(initialWidth===0){initialWidth=$('.members').parents('.middle').width();}
if(initialWidth){wideGrid=!wideGrid;if(dobrado.localStorage){localStorage.membersWideGrid=JSON.stringify(wideGrid);}
if(wideGrid){$('.middle').width('99%');}
else{$('.middle').width(initialWidth);}
if(grid){grid.resizeCanvas();}
columnDisplayWidth=$('#members-column-display').width();$('#members-column-wrapper').width(columnDisplayWidth-buttonWidth);scrollAmount=columnDisplayWidth-150;if(wideGrid){showColumnsLeft();}}}
function updateColumns(){var columns=[allColumns[0]];var columnIds=['username'];$('#members-columns > input:checked').each(function(){var id=$(this).attr('id').match(/([^-]+)$/)[1];$.each(allColumns,function(i,item){if(item.id===id){columns.push(item);columnIds.push(id);return false;}});});var reload=false;var sort='';if(dobrado.localStorage){var currentColumns=JSON.parse(localStorage.membersColumns);if(currentColumns.length===columnIds.length){return;}
var supplierColumnSelected=$.inArray('supplier',columnIds)!==-1;var activeColumnSelected=$.inArray('active',columnIds)!==-1;if(supplierColumnSelected!==supplierColumn){supplierColumn=supplierColumnSelected;reload=true;}
if(activeColumnSelected!==activeColumn){activeColumn=activeColumnSelected;reload=true;}
if(currentColumns.length<columnIds.length){reload=true;}
else{localStorage.membersSortColumns='';}
localStorage.membersColumns=JSON.stringify(columnIds);sort=localStorage.membersSortColumns;}
if(grid){grid.setColumns(columns);if(reload){dobrado.log('Loading new data...','info');$.post('/php/request.php',{request:'members',action:'list',columns:JSON.stringify(columnIds),sort:sort,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'members list')){return;}
localStorage.membersColumns=JSON.stringify(columnIds);if(localStorage.membersSortColumns){sort=localStorage.membersSortColumns;}}
if(grid){grid.resetActiveCell();grid.setSelectedRows([]);grid.setColumns(columns);if(reload){dobrado.log('Loading new data...','info');$.post('/php/request.php',{request:'members',action:'list',columns:JSON.stringify(columnIds),sort:sort,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'members list')){return;}
members=JSON.parse(response);grid.setData(members.data);if(sort!==''){grid.setSortColumns(JSON.parse(sort));}
grid.updateRowCount();grid.render();});}
else{grid.setSortColumns([]);grid.render();}}}
......
......@@ -36,16 +36,6 @@ if (!this.dobrado.members) {
// decide which columns they want to show. It's populated in gridSetup once
// we know if there's a grid module on the page so that Slick is available.
var allColumns = [];
// The total width of all column options to calculate display.
var totalColumnWidth = 0;
var columnDisplayWidth = 0;
// The column display width is reduced by the width of the two control
// buttons to produce the final display area width.
var buttonWidth = 78;
var scrollAmount = 0;
// Store the initial width of the parent container for the grid.
var initialWidth = 0;
var wideGrid = false;
// Track changes to columns that require data to be reloaded.
var supplierColumn = false;
var activeColumn = false;
......@@ -56,19 +46,20 @@ if (!this.dobrado.members) {
return;
}
$('#members-show-columns').prop('checked', false).click(showColumnOptions);
// Clear all the display option checkboxes and set from local storage.
// Clear column display option checkboxes and set from local storage.
$('#members-columns > input').prop('checked', false);
$('#members-wide-grid').prop('checked', false).click(toggleWideGrid);
$('.members input[type=checkbox]').checkboxradio({ icon: false });
$('#members-download').button().click(download);
$('#members-columns').controlgroup().click(updateColumns);
$('#members-show-columns').prop('checked', false).click(function() {
dobrado.grid.showColumns('members', 'options');
});
$('#members-column-left').button({ icon: 'ui-icon-triangle-1-w',
showLabel: false, disabled: true,
}).click(showColumnsLeft);
showLabel: false, disabled: true }).
click(function() { dobrado.grid.showColumns('members', 'left'); });
$('#members-column-right').button({ icon: 'ui-icon-triangle-1-e',
showLabel: false, disabled: false,
}).click(showColumnsRight);
$('#members-columns').controlgroup().click(updateColumns);
showLabel: false, disabled: false }).
click(function() { dobrado.grid.showColumns('members', 'right'); });
// If columns isn't set in local storage create a default.
var columns = JSON.stringify(['username','first','last','email','phone']);
var sort = '';
......@@ -80,6 +71,7 @@ if (!this.dobrado.members) {
sort = localStorage.membersSortColumns;
}
}
dobrado.log('Loading members...', 'info');
$.post('/php/request.php', { request: 'members',
action: 'list',
......@@ -239,7 +231,6 @@ if (!this.dobrado.members) {
grid.onCellChange.subscribe(updateMember);
grid.onSort.subscribe(function(e, args) {
var cols = args.sortCols;
members.data.sort(function(row1, row2) {
for (var i = 0; i < cols.length; i++) {
var field = cols[i].sortCol.field;
......@@ -267,6 +258,9 @@ if (!this.dobrado.members) {
localStorage.membersSortColumns = JSON.stringify(grid.getSortColumns());
}
});
$('#members-wide-grid').prop('checked', false).click(function() {
dobrado.grid.showColumns('members', 'wide', grid);
});
if (dobrado.localStorage) {
if (localStorage.membersWideGrid === 'true') {
// Want to call toggleWideGrid and check the checkbox, this does both.
......@@ -278,77 +272,6 @@ if (!this.dobrado.members) {
}
}
function showColumnOptions() {
$('#members-column-display').toggle();
// Calculate the total column width the first time the options are shown.
if (totalColumnWidth === 0) {
$('#members-columns > label').each(function() {
totalColumnWidth += $(this).outerWidth(true);
});
$('#members-columns').width(totalColumnWidth);
}
columnDisplayWidth = $('#members-column-display').width();
$('#members-column-wrapper').width(columnDisplayWidth - buttonWidth);
// The scroll amount is reduced so that the final button displayed
// doesn't get obscured on both sides of the viewing area.
scrollAmount = columnDisplayWidth - 150;
}
function showColumnsLeft() {
var left = parseInt($('#members-columns').css('margin-left'), 10) +
scrollAmount;
if (left >= 0) {
left = 0;
$('#members-column-left').button({ disabled: true });
}
$('#members-column-right').button({ disabled: false });
$('#members-columns').css('margin-left', left + 'px');
}
function showColumnsRight() {
var left = parseInt($('#members-columns').css('margin-left'), 10) -
scrollAmount;
// The extra amount here is for the left and right buttons.
if (left <= columnDisplayWidth - totalColumnWidth - buttonWidth) {
left = columnDisplayWidth - totalColumnWidth - buttonWidth;
$('#members-column-right').button({ disabled: true });
}
$('#members-column-left').button({ disabled: false });
$('#members-columns').css('margin-left', left + 'px');
}
function toggleWideGrid() {
// Make sure the members module is in the middle section of the layout,
// and then store the initial width so that it can be toggled.
if (initialWidth === 0) {
initialWidth = $('.members').parents('.middle').width();
}
if (initialWidth) {
wideGrid = !wideGrid;
if (dobrado.localStorage) {
localStorage.membersWideGrid = JSON.stringify(wideGrid);
}
if (wideGrid) {
$('.middle').width('99%');
}
else {
$('.middle').width(initialWidth);
}
if (grid) {
grid.resizeCanvas();
}
// Also re-calculate the column options display width.
columnDisplayWidth = $('#members-column-display').width();
$('#members-column-wrapper').width(columnDisplayWidth - buttonWidth);
scrollAmount = columnDisplayWidth - 150;
// In wide mode the options may already be scrolled as far as possible
// to the right, so scroll back to the left.
if (wideGrid) {
showColumnsLeft();
}
}
}
function updateColumns() {
// When updating columns always add the username column first.
var columns = [allColumns[0]];
......@@ -392,9 +315,13 @@ if (!this.dobrado.members) {
localStorage.membersSortColumns = '';
}
localStorage.membersColumns = JSON.stringify(columnIds);
sort = localStorage.membersSortColumns;
if (localStorage.membersSortColumns) {
sort = localStorage.membersSortColumns;
}
}
if (grid) {
grid.resetActiveCell();
grid.setSelectedRows([]);
grid.setColumns(columns);
if (reload) {
dobrado.log('Loading new data...', 'info');
......
This diff is collapsed.
......@@ -163,7 +163,7 @@ if (!this.dobrado.sell) {
// First check if the local data has been saved. If it has then
// all data should be refreshed when the page is loaded.
if (sell.processed && sell.processed.length === 0) {
loadProducts();
loadProducts(false);
}
else if (sell.data && sell.data.length !== 0) {
restorePreviousPurchase();
......@@ -175,9 +175,9 @@ if (!this.dobrado.sell) {
$(".sell .warning").show();
}
if (!sell) {
loadProducts();
}
// Load products only when sell data exists.
var productsOnly = sell ? true : false;
loadProducts(productsOnly);
});
function gridSetup() {
......@@ -423,7 +423,7 @@ if (!this.dobrado.sell) {
return false;
}
function loadProducts() {
function loadProducts(productsOnly) {
dobrado.log("Loading products...", "info");
$.post("/php/request.php", { request: "sell",
action: "list",
......@@ -433,7 +433,13 @@ if (!this.dobrado.sell) {
if (dobrado.checkResponseError(response, "sell list request")) {
return;
}
sell = JSON.parse(response);
var data = JSON.parse(response);
if (productsOnly) {
sell.products = data.products;
}
else {
sell = data;
}
$("#purchase-name-input").autocomplete({ minLength: 2,
search: dobrado.fixAutoCompleteMemoryLeak,
source: sell.users,
......@@ -891,7 +897,7 @@ if (!this.dobrado.sell) {
reloadPage();
}
else {
loadProducts();
loadProducts(false);
}
});
return;
......@@ -942,6 +948,12 @@ if (!this.dobrado.sell) {
$(".sell .done").button("option", "disabled", true);
$(".order .total").html("0.00");
$("#purchase-name-input").val("");
if (purchaseGrid) {
purchaseGrid.setData([]);
purchaseGrid.updateRowCount();
purchaseGrid.render();
purchaseGrid.setSelectedRows([]);
}
$(purchaseGridId).hide();
resetForm();
// If previously in offline mode, saving switches it back.
......@@ -971,19 +983,29 @@ if (!this.dobrado.sell) {
$("#purchase-name-input").val("");
username = "";
}
else if (!confirm('Please make sure existing order for ' + username +
' has been finalised before starting a new sale.')) {
return;
}
$(".sell .done").button("option", "disabled", true);
$(".sell .reset").hide();
$(".order .total").html("0.00");
if (purchaseGrid) {
purchaseGrid.setData([]);
purchaseGrid.updateRowCount();
purchaseGrid.render();
purchaseGrid.setSelectedRows([]);
}
resetForm();
viewPurchases = true;
viewAll();
sell.userIndex[user] = username;
sell.newSales[user] = true;
sell.data[user] = [];
if (dobrado.localStorage) {
localStorage.sell = JSON.stringify(sell);
}
viewPurchases = true;
viewAll();
}
function finishSale() {
......
This diff is collapsed.
This diff is collapsed.
......@@ -49,7 +49,7 @@ function removeAction(cancelled){$.post("/php/request.php",{request:"writer",mod
var writer=JSON.parse(response);history.pushState({},'',writer.url);if(dobrado.editor){dobrado.editor.setData('');}
else{$("#writer-content").val('');}
$("#writer-title").val('');$("#writer-tag-input").val('');$("#writer-webaction-info").html('');$("#writer-author").val(dobrado.readCookie("user"));if(dobrado.reader){dobrado.reader.scrollback(webactionUrl,cancelled);}
webactionType='';webactionUrl='';});}
sendToTwitter=0;sendToFacebook=0;webactionType='';webactionUrl='';});}
function shareFullText(){dobrado.log("Loading content...","info");$.post("/php/request.php",{request:"writer",mode:"shareFullText",share:webactionUrl,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"writer shareFullText")){return;}
var share=JSON.parse(response);if(dobrado.editor){dobrado.editor.setData(share.content);}
else{$("#writer-content").val(share.content);}
......
......@@ -248,6 +248,8 @@ if (!this.dobrado.writer) {
if (dobrado.reader) {
dobrado.reader.scrollback(webactionUrl, cancelled);
}
sendToTwitter = 0;
sendToFacebook = 0;
webactionType = '';
webactionUrl = '';