您的位置:首页 > 其它

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息