Mostrando postagens com marcador JavaScript. Mostrar todas as postagens
Mostrando postagens com marcador JavaScript. Mostrar todas as postagens

sexta-feira, 18 de julho de 2014

Rotina para retornar o diretório temporário do sistema operacional

UseLSX "*javacon"

Function getTempDirectory() As String
   
    On Error GoTo trataerro
   
    Dim t_sesJava As New JavaSession
    Dim t_clsFile As JavaClass
    Set t_clsFile = t_sesJava.GetClass("java/io/File")
    Dim t_mthCreateTemp As JavaMethod
    Set t_mthCreateTemp = t_clsFile.GetMethod("createTempFile", "(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;")
    Dim t_hflFile As JavaObject
   
    Set t_hflFile = t_mthCreateTemp.Invoke(, "tdoc_dir", ".tmp")
   
    Dim strParent As String
   
    strParent = strLeftBack(t_hflFile.getPath(),"\")
   
 
    If InStr(strParent, "/") <> 0 And Right(strParent, 1) <> "/" Then strParent = strParent & "/"
    If InStr(strParent, "\") <> 0 And Right(strParent, 1) <> "\" Then strParent = strParent & "\"
   
    getTempDirectory = strParent
   
   
    Exit Function
trataerro:
    Call AddToStackTrace()
End Function

segunda-feira, 12 de setembro de 2011

Retira Acentos

function retirarAcentos(campo) { var texto = campo.value; var acento = 'áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ'; var semacento = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC'; var nova=''; for (i = 0; i < texto.length; i++) { if (acento.search(texto.substr(i, 1)) >= 0) { nova += semacento.substr(acento.search(texto.substr(i, 1)), 1); } else { nova += texto.substr(i, 1); } } campo.value = nova; }

sexta-feira, 28 de janeiro de 2011

Máscara de campos em Jscript

/**
* Para ser utilizado no evento onKeyPress
* ex:
* CEP -> 99999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* C/C -> 999999-!
* Tel -> (99) 9999-9999
* Hora -> 99:99:99 ou 99:99
* Número -> R$ 99.999,99
*/
function maskField(campo, sMask, event) {

var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
nTecla = event.keyCode;
} else { // Nestcape
nTecla = event.charCode;
}

if(nTecla == 39) return false;

sValue = campo.value;
fldLen = sValue.length;
mskLen = sMask.length;

if (nTecla >= 32) { // Caracteres acima de espaço
if (fldLen < mskLen) { if ((sMask.charAt(fldLen) != "!") && (sMask.charAt(fldLen) != "9")) { sValue = sValue + sMask.charAt(fldLen); campo.value = sValue; if ((nTecla < 48) || (nTecla > 57)) {
return false;
}
} else {
if (sMask.charAt(fldLen) == "9") {
if ((nTecla < 48) || (nTecla > 57)) {
return false;
}
}
}
return true;
} else {
return false;
}
} else { // Caracteres de controle
return true;
}

}







/**
* Use o evento onKeyPress para executar esta função
* ex.:
*
* @param field campo a ser mascarado
* @param maxCharBeforDecimal maximo de caracteres antes da virgula, incluindo os pontos separadores de milhar
* @param event evento do teclado capturado
*
*/
function validateKeyNumber(field, maxCharBeforDecimal, event) {
var valor = field.value
var key;

if(document.all) { // Internet Explorer
key = event.keyCode;
}
else { // Nestcape
key = event.charCode;
}

if (key == 44) {
if (valor == '') {
return false;
}
else if (findVirgula(valor)) {
return false;
}
}
else if (key < 48 || key > 57) {
if (key > 0) {
return false;
}
}

if (valor.length == maxCharBeforDecimal && !findVirgula(valor)) {
if(key != 44 && key != 0) {
return false;
}
}

if (valor.length == 1 && valor.substring(0, 1) == '0') {
if(key != 44 && key != 0) {
return false;
}
}

if (findVirgula(valor)) {
lastCharacter = valor.substring(valor.length - 1, valor.length);

if (lastCharacter != ',') {
index = valor.indexOf(',');
decimal = valor.substring(index + 1, valor.length);

if (decimal.length == 2 && key != 0) {
return false;
}
}
}
return true;
}




/**
* Use o evento onKeyUp para executar esta função
* ex.:
*
* @param field campo a ser mascarado
* @param event evento do teclado capturado
*
*/
function formatMoney(field, event) {
var key;
var valor = field.value;

if(document.all) { // Internet Explorer
key = event.keyCode;
}
else { // Nestcape
key = event.charCode;
}

if (valor.length >= 3 && valor.substring(0, 1) == '0') {
if (valor.substring(1, 2) != ',') {
field.value = valor.substring(1, valor.length)
}
}

if (valor.length > 0 && valor.substring(0, 1) == ',') {
field.value = valor.substring(1, valor.length)
}

if (key != 36 && key != 37 && key != 39 && key != 38 && key != 40 ) {
formatNumber(field)
}

return true;
}

function findVirgula(pDado) {
if(pDado.indexOf(',') > -1) {
return true
}

return false
}

function formatNumber(field) {
dec = ''
arrNum = new Array()
valor = field.value

if (findVirgula(valor)) {
indVirg = valor.indexOf(',')
dec = valor.substring(indVirg, valor.length)
valor = valor.substring(0, indVirg)
}

valor = removePoint(valor)

if (dec != '' && dec.indexOf('.') > -1) {
dec = removePoint(dec)
}

div = valor / 1000

if (div >= 1) {
j = 0

for(i = valor.length; i > 0; i = i - 3) {
if (i - 3 > 0) {
aux = valor.substring(i - 3, i)
arrNum[j++] = '.' + aux
} else {
aux = valor.substring(0, i)
arrNum[j++] = aux
}
}
formattedValue = '';

for(k = j - 1; k >= 0; k--) {
formattedValue += arrNum[k]
}

field.value = formattedValue + dec
}
else {
field.value = valor + dec
}
}

function removePoint(value) {
for(j = 0; j < value.length; j++) { if (value.indexOf('.') > 0) {
j = value.indexOf('.')
aux1 = value.substring(0, j)
aux2 = value.substring(j + 1, value.length)
value = aux1 + aux2
}
}

return value
}

/**
* Use esta função no evento onblur
* ex.:
*
* @param textField campo a ser mascarado
*
*/
function formatDecimal(textField) {
value = textField.value;
indVirg = value.indexOf(',');
isEmpty = value == '';

if (isEmpty) {
return true;
}
if (indVirg == -1) {
value = value + ',00';
textField.value = value;
}
else if (indVirg == value.length - 1) {
value = value + '00';
textField.value = value;
}
else {
decimal = value.substring(indVirg + 1, value.length);

if (decimal.length < 2) { textField.value = value + '0'; } } } /** * Use esta função no evento onblur * ex.:
*
* @param textField campo a ser mascarado
*
*/
function formatDecimal1(textField) {
value = textField.value;
indVirg = value.indexOf(',');
isEmpty = value == '';

if (isEmpty) {
return true;
}
if (indVirg == -1) {
value = value + ',0';
textField.value = value;
}
else if (indVirg == value.length - 1) {
value = value + '0';
textField.value = value;
}
}

sexta-feira, 15 de outubro de 2010

Mascara para qualquer tipo de campo

Uutilizada no evento onkeypress

HORA: return txtBoxFormat(this.form, this.name, '99:99', event);
CEP: return txtBoxFormat(this.form, this.name, '99999-999', event);
TELEFONE: return txtBoxFormat(this.form, this.name, '(99)9999-9999', event);
CPF: return txtBoxFormat(this.form, this.name, '999.999.999-99', event);


function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
nTecla = evtKeyPress.which;
} else {
nTecla = evtKeyPress.which;
if (nTecla == {
return true;
}
}

sValue = objForm[strField].value;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
// toString().replace [transforma em sring e troca elementos por ""]
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( ":", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) { bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ":") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/")) bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ") || (sMask.charAt(i) == ".")) //Se for true utiliza elementos especiais aumenta a máscara if (bolMask) { sCod += sMask.charAt(i); mskLen++; //Caso false mostra o sValue(o q foi digitado) } else { sCod += sValue.charAt(nCount); nCount++; } i++; } objForm[strField].value = sCod; if (nTecla != { // backspace if (sMask.charAt(i-1) == "9") { // apenas números... return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
return true;
}
} else {
return true;
}
}

segunda-feira, 27 de setembro de 2010

Desabilita teclas no browser

function f_KeyDown(evt){
// Captura a tecla Digitada

// code for IE
var evt = window.event;
var pressedKey = String.fromCharCode(evt.keyCode).toLowerCase();

//Desabilita o CTRL-C, V, X e P
if (window.event.ctrlKey && (pressedKey == "c" || pressedKey == "v" || pressedKey == "x" || pressedKey == "p")) {
// disable key press porcessing
cancelKey(evt);
}

//Desabilita o BACKSPACE e ESC.
if ( evt.keyCode==08 || evt.keyCode==27){
// disable key press porcessing
cancelKey(evt);
}
//Desabilita o F5.
if ( evt.keyCode==116){
// disable key press porcessing
cancelKey(evt);
}
}


function cancelKey(evt){

if (evt.preventDefault) {
evt.preventDefault();
return false;
}else {
evt.keyCode = 0;
evt.returnValue = false;
}
}

Desabilita o botão direito no browser

//inserir no header

document.oncontextmenu = function(){return false};

Capturar Teclas Digitadas no browser

function getKey(e){
if (e == null) { // ie
keycode = event.keyCode;
} else { // mozilla
keycode = e.which;
}
key = String.fromCharCode(keycode).toLowerCase();
}
}

quinta-feira, 26 de agosto de 2010

Ler parametros passados via URL

Exemplo da URL:
http://servidor/base.nsf/formulario?Openform&par1=exemplopar1&par2=exemplopar2

Ex 1: Em Formula

NOTES RELEASE 6 EM DIANTE:

parametro1:=@urlQueryString("par1");
parametro2:=@urlQueryString("par2");

valor do parametro1: "exemplopar1"
valor do parametro2: "exemplopar2"

NOTES RELEASE ANTERIOR A 6:

_ArgsNames:=@Left(@Explode(@Right(Query_String_Decoded;"&");"&");"=");
_ArgValues:=@Right(@Explode(@Right(Query_String_Decoded;"&");"&");"=");

parametro1:= @If( _ArgsNames !="";@Do(@If(@Member("par1";_ArgsNames)>0;@GetMembers(_ArgValues;@Member("par1";_ArgsNames); 1); "")); "Sem VALOR")

parametro2:= @If( _ArgsNames !="";@Do(@If(@Member("par2";_ArgsNames)>0;@GetMembers(_ArgValues;@Member("par2";_ArgsNames); 1); "")); "Sem VALOR")


Ex 2: JavaScript

Utilizando a fução getURLParam.

parametro1=getURLParam('par1');
parametro2=getURLParam('par2');

valor do parametro1: "exemplopar1"
valor do parametro2: "exemplopar2"


function getURLParam(strParamName){

var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = "&" + strHref.substr(strHref.indexOf("?") + 1); //.toLowerCase();
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){ if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return strReturn;
},


Ex 3: Lotus Script


Utilizando a fução getURLParam.

'<-- Aqui eu pego o parametro passado pela URL -->
parametro1 = f_retornaParametroURL (Ucase(doccontext.Query_String(0)),"par1")

'<-- Aqui eu pego o parametro passado pela URL -->
parametro2 = f_retornaParametroURL (Ucase(doccontext.Query_String(0)),"par2")


Function f_retornaParametroURL ( qry As String, param As String ) As String
On Error Goto erro

Dim i,j As Integer
Dim result As String

i = Instr(1, qry, param)
result= ""

If i > 0 Then
j = Instr(i, qry, "&")
If j > 0 Then
result$ = Mid(qry, i + Len(param) + 1, (j - 1) - (i + Len(param)))
Else
result$ = Mid(qry, i + Len(param) + 1)
End If
End If
f_retornaParametroURL = result

sai:
Exit Function
erro:
Msgbox "Erro na função f_retornaParametroURL na linha " + Str$(Erl) + " do tipo " + Str$(Err) + ": " + Error$
Resume sai
End Function


 function queryString(parameter) {
 var loc = location.search.substring(1, location.search.length);
 var param_value = false;
 var params = loc.split("&");
 for (i=0; i
 param_name = params[i].substring(0,params[i].indexOf('='));
 if (param_name == parameter) {
 param_value = params[i].substring(params[i].indexOf('=')+1)
 }
 }
 if (param_value) {
 return param_value;
 }
 else {
 return false;
 }

segunda-feira, 16 de agosto de 2010

Função para ocultar ou exibir elemento

/*******************************************************************
Função para exibir o elemento
*******************************************************************/
function f_exibe(elem) {
var el = document.getElementById(elem);

if(el.style.display == 'none'){
el.style.display = 'block';
}else{
el.style.display = 'block';
}
}

/*******************************************************************
Função para ocultar o elemento
*******************************************************************/
function f_esconde(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'none';
}

segunda-feira, 2 de agosto de 2010

FullTrim Js

//++++++++++++++++++++++++++++++++++++++++++++
// Retira brancos de strings antes, depois e excessos do meio
//++++++++++++++++++++++++++++++++++++++++++++
function FullTrim(sStr)
{
var iI = 0;
var iJ = 0;
var iTam = 0;
var sAux = "";

// Verifica string vazia
iTam = sStr.length;
if(iTam==0) return(sStr);

// Localiza primeiro caracter nao espaco
for(iI=0; iI if(sStr.charAt(iI)!=' ') break;

// verifica se String so tinha espacos
if(iI >= iTam) return("");

// Localiza ultimo caracter nao espaco
for(iJ=iTam - 1; iJ>=0; iJ--)
if(sStr.charAt(iJ)!=' ') break;

// Retorna do primeiro ao ultimo nao espaco
// return(sStr.substring(iI,iJ+1));
// adiconado

sStr = sStr.substring(iI,iJ+1);
iTam = sStr.length;
iJ = 0;
for ( iI = 0 ; iI < iTam; iI++)
{
if (sStr.charAt(iI) == ' ') iJ++;
else iJ = 0;
if ( iJ > 1 )
{
sStr= sStr.substring(0,iI-1) + sStr.substring(iI,iTam ) ;
iI = iI -2;
iJ = 0;
}
} // end for
return(sStr);
}

terça-feira, 27 de julho de 2010

Função para maximizar a janela ao abrir

function maxWindow(){
window.moveTo(0,0);
if (document.all){
top.window.resizeTo(screen.availWidth,screen.availHeight);
}else if (document.layers||document.getElementById){
if (top.window.outerHeight top.window.outerHeight = screen.availHeight;
top.window.outerWidth = screen.availWidth;
}
}
}

Seleciona no checkbox/radio o valor passado como parametro

function checkOption(radioName, newValue){
var els = document.getElementsByName(radioName);
if (els.value){
if (els.value == newValue){
els.checked = true;
}
}
for (var i = 0; i < els.length; i++){
if (els[i].value == newValue)
els[i].checked = true;
}
}

Seleciona no combobox o valor passado como parametro

function selectOption(selectName, value) {
var select = document.getElementById(selectName);
var options = select.options;
for (var i = 0; i < options.length; i++) {
var option = options.item(i);
if(option.value == value) {
option.selected = true;
}
}
}

Seleciona todos os valores do ListBox

function selectAllListBox(formName, filterId) {
var check = document.getElementById("filter_" + filterId + "_all");
var select = document.getElementById("filter_" + filterId);
var selected = true;
var options = select.options;
var i = 0;
while (i < options.length && selected) {
var option = options.item(i);
selected = option.selected;
i++;
}
check.checked = selected;
}

Seleciona todos os valores do CheckBox

function selectAllCheckBox( filterId) {
var check = document.getElementById("filter_" + filterId + "_all");
var select = document.getElementById("filter_" + filterId);
var options = select.options;
for(var i = 0; i < options.length; i++) {
var option = options.item(i);
option.selected = check.checked;
}
}

Adiciona valor no combo e ordena

function addToComboboxInOrder(select, value, text) {
var option = document.createElement("option");
option.value = value;
option.innerHTML = text;
for (var i = 0; select.options.length; i++){
if (select.options[i].text.toLowerCase() > text.toLowerCase()){
select.insertBefore(option, select.options[i]);
return;
}
}
select.appendChild(option);
}

Adiciona valor no combo para seleção

function addToCombobox(select, value, text) {
var option = document.createElement("option");
option.value = value;
select.appendChild(option);
var _text = document.createTextNode(text);
option.appendChild(_text);
}

Verifica se existe o valor passado como parametro no combo

function hasItemCombobox(select, value) {
for (var i = 0; i < select.options.length; i++){
if (select.options[i].value == value){
return true;
}
}
return false;
}

Limpa combobox

function clearCombobox(select) {
select.options.length = 0;
select.disabled = false;
}

Função para limpar campos do tipo combo ou text

function limpaCampo(campo){
var oList = document.getElementById(campo);
if ( oList.type =="select-one" || oList.type=="select-multiple" ) {
for (var i = oList.options.length - 1; i >= 0; i--){
oList.options[i] = null;
}
oList.selectedIndex = -1;
}else {
oList.value = ''; // campo texto
}
}