Various changes

This commit is contained in:
Karl Cordes 2009-11-16 14:31:10 +11:00
parent 32199181d6
commit 7e1902089c
12 changed files with 404 additions and 42 deletions

View file

@ -28,17 +28,25 @@ class QuoteProductsController extends AppController {
$this->QuoteProduct->create();
$product = $this->QuoteProduct->Product->findById($this->data['QuoteProduct']['product_id']);
$this->data['QuoteProduct']['description'] = $product['Product']['description'];
$numberOfItems - $this->Quo
/* Copy all the data from the Product to the new QuoteProduct */
$this->data['QuoteProduct']['description'] = $product['Product']['description'];
$this->data['QuoteProduct']['title'] = $product['Product']['title'];
$numberOfItems = $this->QuoteProduct->find('count',
array('conditions' => array('QuoteProduct.quote_id' => $this->data['QuoteProduct']['quote_id'])));
$numberOfItems++;
$this->data['QuoteProduct']['item_number'] = $numberOfItems;
if ($this->QuoteProduct->save($this->data)) {
$quoteid = $this->data['QuoteProduct']['quote_id'];
$this->Session->setFlash(__('Product Added to Quote Successfully', true));
$this->redirect(array('controller'=>'quotes', 'action'=>'view', $quoteid));
} else {
@ -101,23 +109,26 @@ class QuoteProductsController extends AppController {
if (empty($this->data)) {
$this->data = $this->QuoteProduct->read(null, $id);
}
$principles = $this->QuoteProduct->Principle->find('list');
$currencies = $this->QuoteProduct->Currency->find('list');
$quotes = $this->QuoteProduct->Quote->find('list');
$products = $this->QuoteProduct->Product->find('list');
$this->set(compact('principles','currencies','quotes','products'));
$this->set(compact('quotes','products'));
}
function delete($id = null) {
if (!$id) {
$thisQP = $this->QuoteProduct->read(null, $id);
if (!$id) {
$this->Session->setFlash(__('Invalid id for QuoteProduct', true));
$this->redirect(array('action'=>'index'));
}
if ($this->QuoteProduct->del($id)) {
$this->Session->setFlash(__('QuoteProduct deleted', true));
$this->redirect(array('action'=>'index'));
$this->redirect(array('controller'=>'quotes', 'action'=>'view/'.$thisQP['Quote']['id']));
}
}
}
?>

View file

@ -18,7 +18,15 @@ class QuotesController extends AppController {
}
$quote = $this->Quote->read(null, $id);
$this->set('quote', $quote);
$quoteProducts = $this->Quote->QuoteProduct->find('all', array('recursive' => 0, 'conditions' => array('QuoteProduct.quote_id' => $id),
'order' => array('QuoteProduct.item_number ASC'))
);
$this->set('customer', $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']));
$this->set('quoteProducts', $quoteProducts);
}
function add() {

View file

@ -9,7 +9,9 @@ class QuoteProduct extends AppModel {
*/
var $QuoteProduct;
//The Associations below have been created with all possible keys, those that are not needed can be removed
@ -37,5 +39,8 @@ class QuoteProduct extends AppModel {
'foreignKey' => 'id')
);
var $order = "item_number ASC";
}
?>

View file

@ -19,6 +19,7 @@
echo $javascript->link('prototype');
echo $javascript->link('scriptaculous');
echo $javascript->link('ckeditor/ckeditor');
echo $javascript->link('validation');
?>
@ -102,7 +103,7 @@
</ul>
</div>
</div>
<div id="content">
<?php

View file

@ -14,17 +14,6 @@
echo $form->input('description');
echo $form->input('model_number');
echo $form->input('default');
echo $form->input('cost_price');
echo $form->input('exchange_rate');
echo $form->input('our_discount');
echo $form->input('packing_each');
echo $form->input('shipping_weight_each');
echo $form->input('shipping_cost_each');
echo $form->input('duty');
echo $form->input('customs');
echo $form->input('finance');
echo $form->input('misc_cost');
echo $form->input('sell_price');
echo $form->input('notes');
?>
</fieldset>

View file

@ -6,7 +6,7 @@
<?php
echo $form->input('principle_id');
echo $form->input('title');
echo $form->input('title', array('class' => 'required', 'title'=>'Please Enter the Title for the Product'));
echo $form->input('description', array('id' => 'description', 'class'=>'ckeditor'));
//echo $javascript->codeBlock("CKEDITOR.replace('description');");
@ -18,15 +18,22 @@
echo $html->image('calculator.png');
//echo $ajax->div('costingdetails');
//echo $this->element('product_costing', array('modelName' => 'Product'));
//echo $this->e
//lement('product_costing', array('modelName' => 'Product'));
//echo $ajax->divEnd('costingdetails');
?>
</fieldset>
<?php echo $form->end(array('label' => 'Add Product', 'class'=>'wymupdate'));?>
<?php echo $form->end(array('label' => 'Add Product'));
echo $javascript->codeBlock("new Validation('productaddform', {immediate : true, useTitles : true});", array('allowCache'=>true, 'safe'=>false));
?>
</div>
<div class="actions">
<ul>

View file

@ -5,7 +5,11 @@
<?php
echo $form->input('quote_id', array('type' => 'hidden', 'value' => $quote['Quote']['id']));
echo $form->input('principle_id', array('empty' => 'Select a Priniple'));
echo $form->input('quantity', array('class' => 'required validate-number', 'title'=>'Please enter the quantity. It must be a number'));
echo $form->input('principle_id', array('empty' => 'Select a Principle'));
echo $ajax->observeField('QuoteProductPrincipleId', array(
'url' => 'principle_products',
'frequency' => 0.2,
@ -14,8 +18,11 @@
echo $form->input('product_id', array('type' => 'select', 'id'=>'products'));
echo $ajax->observeField('products', array(
echo $ajax->observeField('products', array(
'url' => 'product_options',
'frequency' => 0.2,
'update' => 'productoptions'
@ -24,6 +31,8 @@
echo $ajax->div('productoptions');
echo $ajax->divEnd('productoptions');
//echo '<div id="productoptions"></div>';
//echo $form->select('QuoteProduct.product_id', null, null, array('id'=>'products'));
//*/
@ -53,7 +62,11 @@
?>
</fieldset>
<?php echo $form->end('Submit');?>
<?php echo $form->end('Submit');
echo $javascript->codeBlock("new Validation('QuoteProductAddForm', {immediate : true, useTitles : true});", array('allowCache'=>true, 'safe'=>false));
?>
</div>
<div class="actions">
<ul>

View file

@ -30,8 +30,9 @@ foreach ($options as $opt) {
* If it's an exclusive category, display a drop down box. Otherwise, check boxes
*/
if($opt['ProductOptionsCategory']['exclusive'] == 1) {
echo $form->input($opt['ProductOptionsCategory']['name'],
array('options' => $drop_options, 'default' => $default_option));
echo $form->input('ProductOption.'.$opt['ProductOptionsCategory']['name'],
array('label' => $opt['ProductOptionsCategory']['name'],
'options' => $drop_options, 'default' => $default_option));
}
else {

View file

@ -53,7 +53,7 @@ else {
<div class="related">
<h3><?php __('Products in this Quote');?></h3>
<?php if (!empty($quote['QuoteProduct'])):?>
<?php if (!empty($quoteProducts)):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Item Number'); ?></th>
@ -67,7 +67,7 @@ else {
<?php
$i = 0;
foreach ($quote['QuoteProduct'] as $quoteProduct):
foreach ($quoteProducts as $quoteProduct):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
@ -75,17 +75,17 @@ else {
?>
<tr<?php echo $class;?>>
<td><?php echo $quoteProduct['item_number'];?></td>
<td><?php echo $quoteProduct['option'];?></td>
<td><?php echo number_format($quoteProduct['QuoteProduct']['item_number'], 1, '.', '');?></td>
<td><?php echo $quoteProduct['QuoteProduct']['option'];?></td>
<td><?php echo $quoteProduct['quantity'];?></td>
<td><?php echo $quoteProduct['title'];?></td>
<td><?php echo $quoteProduct['description'];?></td>
<td><?php echo $quoteProduct['QuoteProduct']['quantity'];?></td>
<td><?php echo $quoteProduct['QuoteProduct']['title'];?></td>
<td><?php echo $quoteProduct['QuoteProduct']['description'];?></td>
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'quote_products', 'action'=>'view', $quoteProduct['id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=> 'quote_products', 'action'=>'edit', $quoteProduct['id'])); ?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'quote_products', 'action'=>'delete', $quoteProduct['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $quoteProduct['id'])); ?>
<?php echo $html->link(__('View', true), array('controller'=> 'quote_products', 'action'=>'view', $quoteProduct['QuoteProduct']['id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=> 'quote_products', 'action'=>'edit', $quoteProduct['QuoteProduct']['id'])); ?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'quote_products', 'action'=>'delete', $quoteProduct['QuoteProduct']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $quoteProduct['QuoteProduct']['id'])); ?>
</td>

View file

@ -696,6 +696,43 @@ input#searchbox {
display: auto;
width: 100px;
}
/* CSS from Easy Prototype Validation Script */
input.disabled {
border: 1px solid #F2F2F2;
background-color: #F2F2F2;
}
input.required, textarea.required {
border: 1px solid #00A8E6;
}
input.validation-failed, textarea.validation-failed {
border: 1px solid #FF3300;
color : #FF3300;
}
input.validation-passed, textarea.validation-passed {
border: 1px solid #00CC00;
color : #000;
}
.validation-advice {
margin: 5px 0;
padding: 5px;
background-color: #FF3300;
color : #FFF;
font-weight: bold;
}
.custom-advice {
margin: 5px 0;
padding: 5px;
background-color: #C8AA00;
color : #FFF;
font-weight: bold;
}
/* End CSS from that script */
select {
clear: both;
font-size: 120%;

View file

@ -0,0 +1,10 @@
/**
* Add costing to a product
*
*
*
*/

280
webroot/js/validation.js Executable file
View file

@ -0,0 +1,280 @@
/*
* Really easy field validation with Prototype
* http://tetlaw.id.au/view/javascript/really-easy-field-validation
* Andrew Tetlaw
* Version 1.5.4.1 (2007-01-05)
*
* Copyright (c) 2007 Andrew Tetlaw
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
var Validator = Class.create();
Validator.prototype = {
initialize : function(className, error, test, options) {
if(typeof test == 'function'){
this.options = $H(options);
this._test = test;
} else {
this.options = $H(test);
this._test = function(){return true};
}
this.error = error || 'Validation failed.';
this.className = className;
},
test : function(v, elm) {
return (this._test(v,elm) && this.options.all(function(p){
return Validator.methods[p.key] ? Validator.methods[p.key](v,elm,p.value) : true;
}));
}
}
Validator.methods = {
pattern : function(v,elm,opt) {return Validation.get('IsEmpty').test(v) || opt.test(v)},
minLength : function(v,elm,opt) {return v.length >= opt},
maxLength : function(v,elm,opt) {return v.length <= opt},
min : function(v,elm,opt) {return v >= parseFloat(opt)},
max : function(v,elm,opt) {return v <= parseFloat(opt)},
notOneOf : function(v,elm,opt) {return $A(opt).all(function(value) {
return v != value;
})},
oneOf : function(v,elm,opt) {return $A(opt).any(function(value) {
return v == value;
})},
is : function(v,elm,opt) {return v == opt},
isNot : function(v,elm,opt) {return v != opt},
equalToField : function(v,elm,opt) {return v == $F(opt)},
notEqualToField : function(v,elm,opt) {return v != $F(opt)},
include : function(v,elm,opt) {return $A(opt).all(function(value) {
return Validation.get(value).test(v,elm);
})}
}
var Validation = Class.create();
Validation.prototype = {
initialize : function(form, options){
this.options = Object.extend({
onSubmit : true,
stopOnFirst : false,
immediate : false,
focusOnError : true,
useTitles : false,
onFormValidate : function(result, form) {},
onElementValidate : function(result, elm) {}
}, options || {});
this.form = $(form);
if(this.options.onSubmit) Event.observe(this.form,'submit',this.onSubmit.bind(this),false);
if(this.options.immediate) {
var useTitles = this.options.useTitles;
var callback = this.options.onElementValidate;
Form.getElements(this.form).each(function(input) { // Thanks Mike!
Event.observe(input, 'blur', function(ev) { Validation.validate(Event.element(ev),{useTitle : useTitles, onElementValidate : callback}); });
});
}
},
onSubmit : function(ev){
if(!this.validate()) Event.stop(ev);
},
validate : function() {
var result = false;
var useTitles = this.options.useTitles;
var callback = this.options.onElementValidate;
if(this.options.stopOnFirst) {
result = Form.getElements(this.form).all(function(elm) { return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback}); });
} else {
result = Form.getElements(this.form).collect(function(elm) { return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback}); }).all();
}
if(!result && this.options.focusOnError) {
Form.getElements(this.form).findAll(function(elm){return $(elm).hasClassName('validation-failed')}).first().focus()
}
this.options.onFormValidate(result, this.form);
return result;
},
reset : function() {
Form.getElements(this.form).each(Validation.reset);
}
}
Object.extend(Validation, {
validate : function(elm, options){
options = Object.extend({
useTitle : false,
onElementValidate : function(result, elm) {}
}, options || {});
elm = $(elm);
var cn = elm.classNames();
return result = cn.all(function(value) {
var test = Validation.test(value,elm,options.useTitle);
options.onElementValidate(test, elm);
return test;
});
},
test : function(name, elm, useTitle) {
var v = Validation.get(name);
var prop = '__advice'+name.camelize();
try {
if(Validation.isVisible(elm) && !v.test($F(elm), elm)) {
if(!elm[prop]) {
var advice = Validation.getAdvice(name, elm);
if(advice == null) {
var errorMsg = useTitle ? ((elm && elm.title) ? elm.title : v.error) : v.error;
advice = '<div class="validation-advice" id="advice-' + name + '-' + Validation.getElmID(elm) +'" style="display:none">' + errorMsg + '</div>'
switch (elm.type.toLowerCase()) {
case 'checkbox':
case 'radio':
var p = elm.parentNode;
if(p) {
new Insertion.Bottom(p, advice);
} else {
new Insertion.After(elm, advice);
}
break;
default:
new Insertion.After(elm, advice);
}
advice = Validation.getAdvice(name, elm);
}
if(typeof Effect == 'undefined') {
advice.style.display = 'block';
} else {
new Effect.Appear(advice, {duration : 1 });
}
}
elm[prop] = true;
elm.removeClassName('validation-passed');
elm.addClassName('validation-failed');
return false;
} else {
var advice = Validation.getAdvice(name, elm);
if(advice != null) advice.hide();
elm[prop] = '';
elm.removeClassName('validation-failed');
elm.addClassName('validation-passed');
return true;
}
} catch(e) {
throw(e)
}
},
isVisible : function(elm) {
while(elm.tagName != 'BODY') {
if(!$(elm).visible()) return false;
elm = elm.parentNode;
}
return true;
},
getAdvice : function(name, elm) {
return $('advice-' + name + '-' + Validation.getElmID(elm)) || $('advice-' + Validation.getElmID(elm));
},
getElmID : function(elm) {
return elm.id ? elm.id : elm.name;
},
reset : function(elm) {
elm = $(elm);
var cn = elm.classNames();
cn.each(function(value) {
var prop = '__advice'+value.camelize();
if(elm[prop]) {
var advice = Validation.getAdvice(value, elm);
advice.hide();
elm[prop] = '';
}
elm.removeClassName('validation-failed');
elm.removeClassName('validation-passed');
});
},
add : function(className, error, test, options) {
var nv = {};
nv[className] = new Validator(className, error, test, options);
Object.extend(Validation.methods, nv);
},
addAllThese : function(validators) {
var nv = {};
$A(validators).each(function(value) {
nv[value[0]] = new Validator(value[0], value[1], value[2], (value.length > 3 ? value[3] : {}));
});
Object.extend(Validation.methods, nv);
},
get : function(name) {
return Validation.methods[name] ? Validation.methods[name] : Validation.methods['_LikeNoIDIEverSaw_'];
},
methods : {
'_LikeNoIDIEverSaw_' : new Validator('_LikeNoIDIEverSaw_','',{})
}
});
Validation.add('IsEmpty', '', function(v) {
return ((v == null) || (v.length == 0)); // || /^\s+$/.test(v));
});
Validation.addAllThese([
['required', 'This is a required field.', function(v) {
return !Validation.get('IsEmpty').test(v);
}],
['validate-number', 'Please enter a valid number in this field.', function(v) {
return Validation.get('IsEmpty').test(v) || (!isNaN(v) && !/^\s+$/.test(v));
}],
['validate-digits', 'Please use numbers only in this field. please avoid spaces or other characters such as dots or commas.', function(v) {
return Validation.get('IsEmpty').test(v) || !/[^\d]/.test(v);
}],
['validate-alpha', 'Please use letters only (a-z) in this field.', function (v) {
return Validation.get('IsEmpty').test(v) || /^[a-zA-Z]+$/.test(v)
}],
['validate-alphanum', 'Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed.', function(v) {
return Validation.get('IsEmpty').test(v) || !/\W/.test(v)
}],
['validate-date', 'Please enter a valid date.', function(v) {
var test = new Date(v);
return Validation.get('IsEmpty').test(v) || !isNaN(test);
}],
['validate-email', 'Please enter a valid email address. For example fred@domain.com .', function (v) {
return Validation.get('IsEmpty').test(v) || /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)
}],
['validate-url', 'Please enter a valid URL.', function (v) {
return Validation.get('IsEmpty').test(v) || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v)
}],
['validate-date-au', 'Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.', function(v) {
if(Validation.get('IsEmpty').test(v)) return true;
var regex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
if(!regex.test(v)) return false;
var d = new Date(v.replace(regex, '$2/$1/$3'));
return ( parseInt(RegExp.$2, 10) == (1+d.getMonth()) ) &&
(parseInt(RegExp.$1, 10) == d.getDate()) &&
(parseInt(RegExp.$3, 10) == d.getFullYear() );
}],
['validate-currency-dollar', 'Please enter a valid $ amount. For example $100.00 .', function(v) {
// [$]1[##][,###]+[.##]
// [$]1###+[.##]
// [$]0.##
// [$].##
return Validation.get('IsEmpty').test(v) || /^\$?\-?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}\d*(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/.test(v)
}],
['validate-selection', 'Please make a selection', function(v,elm){
return elm.options ? elm.selectedIndex > 0 : !Validation.get('IsEmpty').test(v);
}],
['validate-one-required', 'Please select one of the above options.', function (v,elm) {
var p = elm.parentNode;
var options = p.getElementsByTagName('INPUT');
return $A(options).any(function(elm) {
return $F(elm);
});
}]
]);