Skip to content
Permalink
Browse files

prefix settings modal

  • Loading branch information...
kilbot committed Aug 19, 2015
1 parent 525671b commit 837b918e5bae4de6c1cee1492d390ade1b2e7f45
@@ -1,5 +1,6 @@
#wc-pos-modal{
.modal {
.wc_pos-modal {
@extend .modal;
z-index: 160000; // seriously
.modal-body {
.form-table {
@@ -10,16 +10,12 @@ module.exports = DualModel.extend({
// this is an array of fields used by FilterCollection.matchmaker()
fields: ['title'],

// the REST API gives string values for some attributes
// this can cause confusion, so parse to float
parse: function(resp){
resp = resp.product || resp;
_.each(['price', 'regular_price', 'sale_price'], function(attr){
if( _.isString(resp[attr]) ){
resp[attr] = parseFloat(resp[attr]);
}
});
return resp;
// data types
schema: {
price : 'number',
regular_price : 'number',
sale_price : 'number',
stock_quantity: 'number'
},

/**
@@ -1,12 +1,19 @@
var Model = require('lib/config/model');
var _ = require('lodash');

module.exports = Model.extend({
name: 'product',
defaults: {
type: 'variation'
},

// data types
schema: {
price : 'number',
regular_price : 'number',
sale_price : 'number',
stock_quantity: 'number'
},

initialize: function(attributes, options){
options = options || {};
this.parent = options.parent;
@@ -20,18 +27,6 @@ module.exports = Model.extend({
self.parent.set({ variations: self.collection.toJSON() });
self.parent.merge();
});
},

// the REST API gives string values for some attributes
// this can cause confusion, so parse to float
parse: function(resp){
resp = resp.product || resp;
_.each(['price', 'regular_price', 'sale_price'], function(attr){
if( _.isString(resp[attr]) ){
resp[attr] = parseFloat(resp[attr]);
}
});
return resp;
}

});
@@ -0,0 +1,2 @@
<h1>{{{title}}}</h1>
<i class="{{iconPrefix}}-times" data-action="close" title="{{close}}"></i>
@@ -1,16 +1,11 @@
var ItemView = require('lib/config/item-view');
var hbs = require('handlebars');
var Tmpl = require('./header.hbs');
var _ = require('lodash');
var polyglot = require('lib/utilities/polyglot');

module.exports = ItemView.extend({
template: hbs.compile('' +
'<h1>{{{title}}}</h1>' +
'<i class="icon icon-times" ' +
'data-action="close" ' +
'title="{{close}}">' +
'</i>'
),
template: hbs.compile(Tmpl),

initialize: function(options){
options = options || {};
@@ -22,6 +17,7 @@ module.exports = ItemView.extend({
},

templateHelpers: function(){
this.data.iconPrefix = window.adminpage ? 'wc_pos-icon' : 'icon';
return this.data;
},

@@ -2,26 +2,27 @@ var LayoutView = require('lib/config/layout-view');
var Header = require('./header');
var _ = require('lodash');
var $ = require('jquery');
var hbs = require('handlebars');
var Tmpl = require('./modal.hbs');
var Radio = require('backbone.radio');
var debug = require('debug')('modalLayout');
require('bootstrap-sass/assets/javascripts/bootstrap/modal');
require('bootstrap-sass/assets/javascripts/bootstrap/transition');

module.exports = LayoutView.extend({
template: function(){
return '<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header"></div>' +
'<div class="modal-body"></div>' +
'<div class="modal-footer"></div>' +
'</div>' +
'</div>';
template: hbs.compile(Tmpl),

//className: 'modal',
className: function(){
// if wp-admin, add css prefix
return window.adminpage ? 'wc_pos-modal' : 'modal';
},
className: 'modal',

attributes: {
'tabindex' : -1,
'role' : 'dialog'
},

buttons: [
{
type: 'message'
@@ -0,0 +1,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"></div>
<div class="modal-body"></div>
<div class="modal-footer"></div>
</div>
</div>
@@ -31,6 +31,7 @@ module.exports = POS.DualModel = DeepModel.extend({

// delayed states
states: {
//'patch' : 'UPDATE_FAILED',
'update' : 'UPDATE_FAILED',
'create' : 'CREATE_FAILED',
'delete' : 'DELETE_FAILED'
@@ -55,10 +56,11 @@ module.exports = POS.DualModel = DeepModel.extend({
options = options || {};
var opts = _.clone(options);
opts.remote = undefined;
var m = method === 'patch' ? 'update' : method;

this.setStatus(method);
this.setStatus(m);

return DeepModel.prototype.sync.call(this, method, model, opts)
return DeepModel.prototype.sync.call(this, m, model, opts)
.then(function(){
if(options.remote){
return model.remoteSync(method, model, options);
@@ -70,9 +72,10 @@ module.exports = POS.DualModel = DeepModel.extend({
model = model || this;
options = options || {};
options.remote = true;
if(method !== 'read'){
method = model.getMethod(method);
}

//if(method !== 'read'){
// method = model.getMethod(method);
//}
return DeepModel.prototype.sync.call(this, method, model, options)
.then(function(resp){
if(resp){
@@ -91,16 +94,16 @@ module.exports = POS.DualModel = DeepModel.extend({
}
},

getMethod: function(method){
var status = this.get('status');
var remoteMethod = _.findKey(this.states, function(state) {
return state === status;
});
if(remoteMethod){
return remoteMethod;
}
return method;
},
//getMethod: function(method){
// var status = this.get('status');
// var remoteMethod = _.findKey(this.states, function(state) {
// return state === status;
// });
// if(remoteMethod){
// return remoteMethod;
// }
// return method;
//},

merge: function(resp){
// todo: merge
@@ -1,13 +1,43 @@
var bb = require('backbone');
var POS = require('lib/utilities/global');
var _ = require('lodash');
//var Radio = require('backbone.radio');

// parsing functions
var parse = {
'float': parseFloat,
'int': parseInt,
'number': Number
};

module.exports = POS.Model = bb.Model.extend({

constructor: function() {
bb.Model.apply(this, arguments);
},

parse: function (resp){
return resp && resp[this.name] ? resp[this.name] : resp ;
var data = resp[this.name] || resp;
if( ! data ){
return;
}

// check data type
_.each( this.schema, function( val, attr ) {

// if attribute exists
if( ! _.has( data, attr ) ){
return;
}

// string, eg: 'float'
if( _.isString(val) && parse[val] ){
data[attr] = parse[val]( data[attr] );
}

}, this);

return data;
}

});
@@ -20,8 +20,10 @@ public function __construct() {
return;
// remove wc api authentication
$wc_api_auth = WC()->api->authentication;
remove_filter( 'woocommerce_api_check_authentication', array( $wc_api_auth, 'authenticate' ), 0 );
// - relies on ->api and ->authentication being publicly accessible
if( isset( WC()->api ) && isset( WC()->api->authentication ) ){
remove_filter( 'woocommerce_api_check_authentication', array( WC()->api->authentication, 'authenticate' ), 0 );
}
// support for X-HTTP-Method-Override for WC < 2.4
if( version_compare( WC()->version, '2.4', '<' ) && isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']) ){
@@ -59,7 +61,7 @@ public function wc_api_authentication() {
public function dispatch_args($args, $callback){
$wc_api_handler = get_class($callback[0]);
$has_data = in_array( $args['_method'], array(2, 4, 6) ) && isset( $args['data'] ) && is_array($args['data']);
$has_data = in_array( $args['_method'], array(2, 4, 8) ) && isset( $args['data'] ) && is_array( $args['data'] );
if( $has_data ){
// remove status
if( array_key_exists('status', $args['data']) ){
@@ -17,8 +17,8 @@ class WC_POS_Products {
*/
public function __construct() {
$this->init();
add_action( 'woocommerce_product_set_stock', array( $this, 'product_set_stock') );
add_action( 'woocommerce_variation_set_stock', array( $this, 'product_set_stock') );
}
/**
@@ -41,9 +41,10 @@ private function init() {
/**
* Bump modified date on stock change
* - variation->id = parent id
* @param $product
*/
public function product_set_stock($product){
public function product_set_stock( $product ){
$post_modified = current_time( 'mysql' );
$post_modified_gmt = current_time( 'mysql', 1 );
wp_update_post( array(
@@ -82,8 +82,10 @@ Bugs can be reported on the [WooCommerce POS GitHub repository](https://github.c
* New: option to automatically print receipt after checkout - commit [16fba05](https://github.com/kilbot/WooCommerce-POS/commit/16fba054593e118be6c567ce4d87f8d0b91acaa5)
* Fix: variation display and select issues - commit [91c7ec1](https://github.com/kilbot/WooCommerce-POS/commit/91c7ec13e737f820d84feb7890d7b6d027a79792), [b3d6543](https://github.com/kilbot/WooCommerce-POS/commit/b3d6543b86140df62ff90f3a7b7e734d73ae59ab)
* Fix: variation barcode search for products in queue - commit [3fda531](https://github.com/kilbot/WooCommerce-POS/commit/3fda5317ef580f6b6d70e24ba235d2b7e69c5ee4)
* Fix: variation stock adjustment after sale - commit []()
* Fix: populate order addresses from customer id - commit [b86bc56](https://github.com/kilbot/WooCommerce-POS/commit/b86bc5650a2bf41d7744bf07cda34407e8fa3dd5)
* Fix: compatibility fix for WC 2.4 SSL authentication - commit []()
* Fix: compatibility fix for WC 2.4 SSL authentication - commit [525671b](https://github.com/kilbot/WooCommerce-POS/commit/525671b7613b20864366aebf426f14d07b37bfa4)
* Fix: modal CSS conflict in WP Admin - commit []()
* Tweak: WP Admin CSS - commit [c5a38c7](https://github.com/kilbot/WooCommerce-POS/commit/c5a38c7f889a7788e3eaa633c28620d2e80ac2ee)

= 0.4.1 =
@@ -1,4 +1,5 @@
describe('lib/config', function () {
require('./config/model');
require('./config/dual-model');
require('./config/dual-collection');
});
@@ -0,0 +1,41 @@
describe('lib/config/model.js', function () {

var Model = require('lib/config/model.js');

// WC REST API outputs nested json, mixed data types
var wc_rest_api_output = {
'product': {
id: 99, // number
price: '9.99', // string
stock_quantity: '', // string or number
managing_stock: false // boolean
}
};

it('should be in a valid state', function() {
var model = new Model();
model.should.be.ok;
});

it('should parse WC REST API data', function() {
var Product = Model.extend({
name: 'product'
});
var model = new Product( wc_rest_api_output, { parse: true } );
model.id.should.eql(99);
});

it('should convert attributes to given schema', function() {
var Product = Model.extend({
name: 'product',
schema: {
price: 'number',
stock_quantity: 'number'
}
});
var model = new Product( wc_rest_api_output, { parse: true } );
model.get('price').should.eql(9.99);
model.get('stock_quantity').should.eql(0);
});

});

0 comments on commit 837b918

Please sign in to comment.
You can’t perform that action at this time.