martes, 27 de noviembre de 2012

SharePoint 2010 KeywordQuery searchs in SPLists & Document Libraries

private ResultTableCollection RearlizarLaBusqueda(Busqueda busqueda)
{
    ResultTableCollection resultado = new ResultTableCollection();
    using (SPSite sitio = new SPSite(_url))
    {
        KeywordQuery consulta = new KeywordQuery(sitio);
        consulta = ConfigurarConsulta(consulta, busqueda);
        if (_validador.EsValidaLaConsulta(consulta))
        { resultado = consulta.Execute(); }
    }
    return resultado;
}

private KeywordQuery ConfigurarConsulta(KeywordQuery consulta, Busqueda busqueda)
{
    var nombresDeListas = ConseguirListasPorModulo(busqueda.Ambito);
    var resultado = consulta;
    string hiddenConstraints = ConfigurarElHiddenConstraints(_url, nombresDeListas);

    resultado.IgnoreAllNoiseQuery = true;
    resultado.KeywordInclusion = KeywordInclusion.AllKeywords;
    resultado.EnableStemming = true;
    resultado.TrimDuplicates = false;
    resultado.ResultTypes = ResultType.RelevantResults;
    resultado.HiddenConstraints = hiddenConstraints;
    resultado.QueryText = busqueda.Texto;
    return resultado;
}

private List ConseguirListasPorModulo(string nombreDelModulo)
{
    var resultado = new List();
    if (string.IsNullOrEmpty(nombreDelModulo))
    {
        resultado = ConseguirTodosLosNombresDeLasListasDeTodosLosModulosPermitidos();
    }
    else 
    {
        resultado = _gestorConfiguracionBusqueda.ConseguirLosNombresDeLasListasPorNombreDeModulo(nombreDelModulo);
    }
    return resultado;
    
}

private string ConfigurarElHiddenConstraints(string url, List nombresDeListas)
{
    StringBuilder ambitos = new StringBuilder(string.Empty);
    string direccionDeLista = string.Empty;
    var urlLista = string.Empty;
    for (int contador = 0; contador < nombresDeListas.Count; contador++)
    {
        urlLista = ConstruirUrlLista(url, nombresDeListas[contador]);
        direccionDeLista = string.Format("site:\"{0}\"", urlLista);
        ambitos.Append(direccionDeLista);
        if (contador + 1 < nombresDeListas.Count) 
        {
           ambitos.Append(" OR ");

        }
   }
   return ambitos.ToString();
}

private string ConstruirUrlLista(string url, string nombreLista)
{
    using(SPSite site = new SPSite(url))
    using (SPWeb web = site.OpenWeb())
    {
       var lista = web.Lists.TryGetList(nombreLista);
       if (lista != null)
       {
           return lista.ParentWeb.Url + "/" + lista.RootFolder.Url + "/";
       }
       throw new Exception("Nombre de lista no encontrada");
    }
}

lunes, 19 de noviembre de 2012

loading animation with JQuery-BlockUI

When the dats are loading from the server, i needed a loading page animation. I´ve dicovered BlockUI
This the code:


   



viernes, 16 de noviembre de 2012

Scopes in Javascript

   window.color = “red”; //<-- general scope everything without a scope
   var object = { color: “blue” };
   function sayColor(){
     //alert(this.color);
   }
   sayColor(); //”red” without scope
   o.sayColor = sayColor;
   o.sayColor(); //”blue” inside a object/function

Function Declarations vs. Function Expressions

A Function Declaration is:
function add(numberOne, numberTwo){
    return numberOne + numberTwo;
}
A Function Expressions is:
var add = function(numberOne, numberTwo){
      return numberOne + numberTow;
};
When we write a function declaration, it's loaded in the execution context, before the script runs, but when we write a function expresion, the interpreter, load while it's executing the code. So we can find a simple error.
//alert(add(10,10)); the vm doesn't found the function add(), because it's not loaded
var add = function(numberOne, numberTwo){
      return numberOne + numberTow;
};

My first Class in Javascript: Manage the Html tag select

//objeto que describe cada uno de los 
//options del Select|Combo
function ComboOption(texto, valor) {
    this.texto = texto;
    this.valor = valor;
}

//Gestiona las posibles operaciones sobre el control
//HTML 
function GestorCombo(idCombo) {
    this.combo = document.getElementById(idCombo);
    if (this.combo == null) { return; }

    this.borrarTodasLasOpciones = function () {

        var i;
        for (i = this.combo.length - 1; i >= 0; i--) {
            if (this.combo.options[i].selected) {
                this.combo.remove(i);
            }
        }
    }

    this.aniadirOption = function (option) {
        this.combo.options[this.combo.options.length] = new Option(option.texto, option.valor);
    }

    this.conseguirValorSeleccionado = function () {
        var resultado = '';
        if ((this.combo.selectedIndex > -1) && (this.combo.options.length > 0)) {
            resultado = this.combo.options[this.combo.selectedIndex].value;
        }
        return resultado;
    }

    this.seleccionarOption = function (valor) {
        for (i = 0; i < this.combo.options.length; i++) {
            if (this.combo.options[i].value == valor) { break; } 
        }
        this.combo.options.selectedIndex = i;
    }
}

martes, 13 de noviembre de 2012

Brian Crain

A new piano author appears in my life, he's Brian Crain some music of him.
Happy listening!!!

Ordering Asc & Desc In Javascript

It's aMazing and so easy!!! Here it's the code
  function orderDescending(valueOne, valueTwo){
   if(valueTwo > valueOne){
    return 1;
   }
   if (valueTwo < valueOne) {
    return -1;
   }
   else{return 0;}
  }
  function orderAscending(valueOne, valueTwo){
   if(valueTwo > valueOne){
    return -1;
   }
   if (valueTwo < valueOne) {
    return 1;
   }
   else{return 0;} 
  }

  var numbers = [1,4,27,4,8,0];

  numbers.sort(orderAscending);
  //alert(numbers);

  numbers.sort(orderDescending);
  //alert(numbers);

But We can improve it, in this way ...
function Comparator(propertyName) {
   return function(objectOne, objectTwo){
   var valueOne = objectOne[propertyName];
   var valueTwo = objectTwo[propertyName];
   if (value1 < value2){
     return -1;
   } else if (value1 > value2){
      return 1;
   } else {
      return 0;
   }
   };
}
And We can use it in this way
var data = [{name: “PersonOne”, age: 1}, {name: “PersonTwo”, age: 2}];
data.sort(Comparator(“name”));