custom sugarcrm birthdate
2012-04-06 11:22
323 查看
class DateValidate {
function validate($event, $arguments)
{
$datereg = $GLOBALS['timedate']->get_regular_expression($GLOBALS['timedate']->get_date_format());
foreach ($datereg['positions'] as $type => $pos) {
if (empty($date_pos)) {
$date_pos .= "'$type': $pos";
} else {
$date_pos .= ",'$type': $pos";
}
}
$format = $GLOBALS['timedate']->get_date_format();
$newFormat = '';
$wildcard = '';
foreach (str_split($format) as $char) {
if($char == "m")
$newFormat .= "MM";
else if($char == "d")
$newFormat .= "DD";
else if($char == "Y")
$newFormat .= "YYYY";
else
{$newFormat .= $char;$wildcard = $char;}
}
//require_once('include/formbase.php');
global $action;
$GLOBALS['log']->debug("whichaction:".$action);
if(!empty($action) && $action== "EditView"){
echo '<script>
first_load = true;
is_set = false;
dateformat = "'. $newFormat .'";
wildcard = "'. $wildcard .'";
function clear(){
//if(first_load)
//{
bdinput.value = "";bdinput.style.color="black";first_load = false;
//}
}
var Event = YAHOO.util.Event;
var Dom = YAHOO.util.Dom;
var showButton = "birthdate_trigger";
var showButtonElement = Dom.get(showButton);
Event.on(showButtonElement, "click", function() {clear();})
date_reg_format = "' .$datereg['format']. '";
date_reg_positions = {' .$date_pos. '};
String.prototype.insertChar = function(index, text) {
if (index > this.length - 1) index = this.length;
if (index < 0) index = 0;
return this.substring(0, index) + text + this.substring(index);
}
bdinput = document.getElementById("birthdate");
bdimage = document.getElementById("birthdate_trigger");
savebutton = document.getElementById("SAVE_FOOTER");
//check whether the value of input is set?
if(bdinput.value!= "")
{bdinput.style.color="black";is_set = true;}
else
{bdinput.value=dateformat;bdinput.style.color="gray";}
savebutton.onclick = function (){
if(first_load && !is_set)
//clear up the value if user creates or edits a no birthdate contact
{clear();}
this.form.action.value="Save";
if(check_form("EditView"))SUGAR.ajaxUI.submitForm(this.form);
return false;};
//savebutton.addEventListener("click", function (){if(first_load) {bdinput.value=""}}, false);
date_positions = new Array(3);
date_reg_format_custom = "([0-9]{8})";
i = 0;m = "";d = "";y = "";m_size = 2;d_size = 2;y_size = 4;
//p = date_reg_format.indexOf(")");
//date_wildcard = date_reg_format.charAt(p + 1);
//dateParts = this.value.match(date_reg_format);
for (key in date_reg_positions) {
index = date_reg_positions[key];
if (key == "m") {
//m = dateParts[index];
date_positions[i] = m_size;
} else if (key == "d") {
//d = dateParts[index];
date_positions[i] = d_size;
} else {
//y = dateParts[index];
date_positions[i] = y_size;
}
i = i + 1;
}
bdinput.onfocus = function() {
if(first_load && !is_set) {clear(); return true;}
else {
this.value = this.value.replace(/(\/|\-|\.)/g, "");
return true;
}
};
bdinput.onblur = function() {
myregexp = new RegExp(date_reg_format_custom);
if(this.value=="") {first_load =true;this.value =dateformat;this.style.color="gray";return false;}
else {
if (!myregexp.test(this.value)) {return false;}
else {
var v = this.value;
for (k = 0, po = 0; k < 2; k++) {
po = po + date_positions[k]
v=v.insertChar(po, wildcard);
po++;
}
this.value = v;
return true;
}
return true;}
};
</script>';
}
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=768px, maximum-scale=1.0" />
<title>sketchpad</title>
<script type="text/javascript" charset="utf-8">
function get_X(obj){
var ParentObj=obj;
var left=obj.offsetLeft;
while(ParentObj=ParentObj.offsetParent){
left+=ParentObj.offsetLeft;
}
return left;
}
function get_Y(obj){
var ParentObj=obj;
var top=obj.offsetTop;
while(ParentObj=ParentObj.offsetParent){
top+=ParentObj.offsetTop;
}
return top;<
bae3
br />}
window.addEventListener('load',function(){
// get the canvas element and its context
var canvas = document.getElementById('sketchpad');
var context = canvas.getContext('2d');
//div absolute coordinate
canvas_x = get_X(canvas);
canvas_y = get_Y(canvas);
context.strokeStyle = '#0074CC';
context.beginPath();
context.moveTo(70,180);
context.lineTo(670,180);
context.closePath();
context.stroke();
context.strokeStyle = 'black';
// create a drawer which tracks touch movements
var drawer = {
isDrawing: false,
mousedown: function(coors){
context.beginPath();
context.moveTo(coors.x, coors.y);
//alert(coors.x+ ',' +coors.y)
this.isDrawing = true;
},
mousemove: function(coors){
if (this.isDrawing) {
context.lineTo(coors.x, coors.y);
context.stroke();
}
},
mouseup: function(coors){
if (this.isDrawing) {
this.mousemove(coors);
this.isDrawing = false;
}
}
};
// create a function to pass touch events and coordinates to drawer
function draw(event){
// get the touch coordinates
var coors = {
x: event.pageX - canvas_x,//.targetTouches[0]
y: event.pageY - canvas_y
};
// pass the coordinates to the appropriate handler
drawer[event.type](coors);
}
// attach the touchstart, touchmove, touchend event listeners.
canvas.addEventListener('mousedown',draw, false);
canvas.addEventListener('mousemove',draw, false);
canvas.addEventListener('mouseup',draw, false);
// prevent elastic scrolling
document.body.addEventListener('mousemove',function(event){
event.preventDefault();
},false);
// end body.onTouchMove
},false);
// end window.onLoad
function clear_canvas(){
var canvas = document.getElementById('sketchpad');
var context = canvas.getContext('2d');
if(context) {
//canvas.width = canvas.width;
context.clearRect ( 0 , 0 , canvas.width , canvas.height );
context.strokeStyle = '#0074CC';
context.beginPath();
context.moveTo(70,180);
context.lineTo(670,180);
context.closePath();
context.stroke();
context.strokeStyle = 'black';
}
}
function send(){
var canvas = document.getElementById('sketchpad');
var img = canvas.toDataURL('image/png');
document.getElementById('tt').value = img;
//alert(img);
return false;
}
</script>
<link rel="stylesheet" type="text/css" href="bootstrap.css">
<style type="text/css">
h3 {
display: inline;
}
.container2 {
border: 1px solid black;
padding: 10%; *
zoom: 1;
}
</style>
</head>
<body>
<div class="container" style="">
<div class="container2">
<form>
<table width="100%">
<tr>
<td>
<h3>Enter your initial</h3>
</td>
<tr></tr>
<td><input id="tt" class="input-xlarge" /></td>
</tr>
<tr>
<td>
<h3>Drwa your initial</h3>
 <a href="#" onclick="clear_canvas()">Clear</a></td>
</tr>
<tr>
<td><canvas style="border:1px solid #ccc" id="sketchpad"
width="740" height="240"> Sorry, your browser is not
supported. </canvas></td>
</tr>
<tr>
<td>
<a class="btn btn-primary" onclick="send();">Apply</a>
 
<button class="btn">Cancel</button>
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
function validate($event, $arguments)
{
$datereg = $GLOBALS['timedate']->get_regular_expression($GLOBALS['timedate']->get_date_format());
foreach ($datereg['positions'] as $type => $pos) {
if (empty($date_pos)) {
$date_pos .= "'$type': $pos";
} else {
$date_pos .= ",'$type': $pos";
}
}
$format = $GLOBALS['timedate']->get_date_format();
$newFormat = '';
$wildcard = '';
foreach (str_split($format) as $char) {
if($char == "m")
$newFormat .= "MM";
else if($char == "d")
$newFormat .= "DD";
else if($char == "Y")
$newFormat .= "YYYY";
else
{$newFormat .= $char;$wildcard = $char;}
}
//require_once('include/formbase.php');
global $action;
$GLOBALS['log']->debug("whichaction:".$action);
if(!empty($action) && $action== "EditView"){
echo '<script>
first_load = true;
is_set = false;
dateformat = "'. $newFormat .'";
wildcard = "'. $wildcard .'";
function clear(){
//if(first_load)
//{
bdinput.value = "";bdinput.style.color="black";first_load = false;
//}
}
var Event = YAHOO.util.Event;
var Dom = YAHOO.util.Dom;
var showButton = "birthdate_trigger";
var showButtonElement = Dom.get(showButton);
Event.on(showButtonElement, "click", function() {clear();})
date_reg_format = "' .$datereg['format']. '";
date_reg_positions = {' .$date_pos. '};
String.prototype.insertChar = function(index, text) {
if (index > this.length - 1) index = this.length;
if (index < 0) index = 0;
return this.substring(0, index) + text + this.substring(index);
}
bdinput = document.getElementById("birthdate");
bdimage = document.getElementById("birthdate_trigger");
savebutton = document.getElementById("SAVE_FOOTER");
//check whether the value of input is set?
if(bdinput.value!= "")
{bdinput.style.color="black";is_set = true;}
else
{bdinput.value=dateformat;bdinput.style.color="gray";}
savebutton.onclick = function (){
if(first_load && !is_set)
//clear up the value if user creates or edits a no birthdate contact
{clear();}
this.form.action.value="Save";
if(check_form("EditView"))SUGAR.ajaxUI.submitForm(this.form);
return false;};
//savebutton.addEventListener("click", function (){if(first_load) {bdinput.value=""}}, false);
date_positions = new Array(3);
date_reg_format_custom = "([0-9]{8})";
i = 0;m = "";d = "";y = "";m_size = 2;d_size = 2;y_size = 4;
//p = date_reg_format.indexOf(")");
//date_wildcard = date_reg_format.charAt(p + 1);
//dateParts = this.value.match(date_reg_format);
for (key in date_reg_positions) {
index = date_reg_positions[key];
if (key == "m") {
//m = dateParts[index];
date_positions[i] = m_size;
} else if (key == "d") {
//d = dateParts[index];
date_positions[i] = d_size;
} else {
//y = dateParts[index];
date_positions[i] = y_size;
}
i = i + 1;
}
bdinput.onfocus = function() {
if(first_load && !is_set) {clear(); return true;}
else {
this.value = this.value.replace(/(\/|\-|\.)/g, "");
return true;
}
};
bdinput.onblur = function() {
myregexp = new RegExp(date_reg_format_custom);
if(this.value=="") {first_load =true;this.value =dateformat;this.style.color="gray";return false;}
else {
if (!myregexp.test(this.value)) {return false;}
else {
var v = this.value;
for (k = 0, po = 0; k < 2; k++) {
po = po + date_positions[k]
v=v.insertChar(po, wildcard);
po++;
}
this.value = v;
return true;
}
return true;}
};
</script>';
}
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=768px, maximum-scale=1.0" />
<title>sketchpad</title>
<script type="text/javascript" charset="utf-8">
function get_X(obj){
var ParentObj=obj;
var left=obj.offsetLeft;
while(ParentObj=ParentObj.offsetParent){
left+=ParentObj.offsetLeft;
}
return left;
}
function get_Y(obj){
var ParentObj=obj;
var top=obj.offsetTop;
while(ParentObj=ParentObj.offsetParent){
top+=ParentObj.offsetTop;
}
return top;<
bae3
br />}
window.addEventListener('load',function(){
// get the canvas element and its context
var canvas = document.getElementById('sketchpad');
var context = canvas.getContext('2d');
//div absolute coordinate
canvas_x = get_X(canvas);
canvas_y = get_Y(canvas);
context.strokeStyle = '#0074CC';
context.beginPath();
context.moveTo(70,180);
context.lineTo(670,180);
context.closePath();
context.stroke();
context.strokeStyle = 'black';
// create a drawer which tracks touch movements
var drawer = {
isDrawing: false,
mousedown: function(coors){
context.beginPath();
context.moveTo(coors.x, coors.y);
//alert(coors.x+ ',' +coors.y)
this.isDrawing = true;
},
mousemove: function(coors){
if (this.isDrawing) {
context.lineTo(coors.x, coors.y);
context.stroke();
}
},
mouseup: function(coors){
if (this.isDrawing) {
this.mousemove(coors);
this.isDrawing = false;
}
}
};
// create a function to pass touch events and coordinates to drawer
function draw(event){
// get the touch coordinates
var coors = {
x: event.pageX - canvas_x,//.targetTouches[0]
y: event.pageY - canvas_y
};
// pass the coordinates to the appropriate handler
drawer[event.type](coors);
}
// attach the touchstart, touchmove, touchend event listeners.
canvas.addEventListener('mousedown',draw, false);
canvas.addEventListener('mousemove',draw, false);
canvas.addEventListener('mouseup',draw, false);
// prevent elastic scrolling
document.body.addEventListener('mousemove',function(event){
event.preventDefault();
},false);
// end body.onTouchMove
},false);
// end window.onLoad
function clear_canvas(){
var canvas = document.getElementById('sketchpad');
var context = canvas.getContext('2d');
if(context) {
//canvas.width = canvas.width;
context.clearRect ( 0 , 0 , canvas.width , canvas.height );
context.strokeStyle = '#0074CC';
context.beginPath();
context.moveTo(70,180);
context.lineTo(670,180);
context.closePath();
context.stroke();
context.strokeStyle = 'black';
}
}
function send(){
var canvas = document.getElementById('sketchpad');
var img = canvas.toDataURL('image/png');
document.getElementById('tt').value = img;
//alert(img);
return false;
}
</script>
<link rel="stylesheet" type="text/css" href="bootstrap.css">
<style type="text/css">
h3 {
display: inline;
}
.container2 {
border: 1px solid black;
padding: 10%; *
zoom: 1;
}
</style>
</head>
<body>
<div class="container" style="">
<div class="container2">
<form>
<table width="100%">
<tr>
<td>
<h3>Enter your initial</h3>
</td>
<tr></tr>
<td><input id="tt" class="input-xlarge" /></td>
</tr>
<tr>
<td>
<h3>Drwa your initial</h3>
 <a href="#" onclick="clear_canvas()">Clear</a></td>
</tr>
<tr>
<td><canvas style="border:1px solid #ccc" id="sketchpad"
width="740" height="240"> Sorry, your browser is not
supported. </canvas></td>
</tr>
<tr>
<td>
<a class="btn btn-primary" onclick="send();">Apply</a>
 
<button class="btn">Cancel</button>
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
相关文章推荐
- SugarCRM ListView中去掉导出
- Custom Date Format。
- Implementing Sugarcrm: A Step-by-step Guide to Using This Powerful Open Source Application in Your B
- Custom Date and Time Format Strings
- SugarCRM ListView中只显示高级查询
- Custom Date tag
- Spring inject Date into bean property – CustomDateEditor
- Custom Date and Time Format Strings
- Spring注入日期到bean属性-CustomDateEditor
- Sugarcrm Email Integration
- 在CentOS下源码安装SugarCRM Pro / CE 5.0.0 (待续)
- Calculating Age From Date of Birth In PHP
- sugarcrm rest api 实现流程
- java-SimpleDateFormatDemo & BirthDemo
- java-SimpleDateFormatDemo & BirthDemo
- 使用sugar crm rest api 创建联系人时有概率返回被删除的联系人的id
- SugarCRM活动 What's New in SugarCRM 7
- SugarCRM活动 Introduction to SugarCRM
- Dynamics CRM custom plugin
- Format Date in Custom Drop Down List in Ext.Net