andlio

Untitled

May 16th, 2012
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. define([
  2.     "dojo/dom-style",
  3.     "dojo/_base/declare",
  4.     "dojo/_base/event",
  5.     "dojo/on",
  6.     "dijit/_TemplatedMixin",
  7.     "dijit/_WidgetsInTemplateMixin",
  8.     "dijit/_WidgetBase",
  9.     "dojo/text!./templates/MocsSearchPanel.html",
  10.     "dojo/_base/xhr",
  11.     "lib/utils",
  12.     "dijit/form/Button",
  13.     "dijit/form/TextBox",
  14.     "dojox/form/Manager",
  15.     "widgets/grids/MocsGrid"
  16. ], function(domStyle, declare, Event, on, _TemplatedMixin, _WidgetsInTemplateMixin, _WidgetBase, template, xhr, utils){
  17.     return declare("widgets.panels.MocsSearchPanel", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
  18.         // Path to template
  19.         templateString : template,
  20.         // Properties
  21.         allowNullSelection:false,
  22.         clearOnSelect:true,
  23.         projectId:0,
  24.         // PostCreate
  25.         postCreate:function(){
  26.             /**
  27.              * Call super
  28.              */
  29.             this.inherited(arguments);
  30.             /**
  31.              * Disable selection
  32.              */
  33.             this.disableSelection();
  34.             /**
  35.              * Connect the search form
  36.              */
  37.             if(null!=this.searchForm){
  38.                 this.searchForm.on("submit", dojo.hitch(this, "_onSearch"));
  39.             }
  40.            
  41.             /**
  42.              * Connect the buttons
  43.              */
  44.             on(this.selectBtn, "onClick", this, "_onSelect");
  45.             on(this.resultsGrid, "onSelectionChanged", this, "_onSelectionChange");
  46.            
  47.         },
  48.         /**
  49.          * Called when the search is clicked.
  50.          */
  51.         _onSearch:function(event){
  52.             // Stop the submit event
  53.             Event.stop(event);
  54.             // Create the variables
  55.             var _this = this,
  56.                 criteria = this.searchForm.gatherFormValues(),
  57.                 criteriaAreValids = false;
  58.             /**
  59.              * Check the project id
  60.              */
  61.             if(null == this.projectId){
  62.                 utils.showError("Invalid project. Please reload the page.");
  63.                 return false;
  64.             }
  65.             /**
  66.              * Clear the results grid
  67.              */
  68.             this.resultsGrid.reset();
  69.             /**
  70.              * Check the criteria
  71.              */
  72.             for(var key in criteria){
  73.                 if(criteria[key]!=null && criteria[key].length>=3) criteriaAreValids = true;
  74.             }
  75.            
  76.             if(!criteriaAreValids){
  77.                 utils.showError("Almost one criterion must have 3 caracters or more.");
  78.                 return false;
  79.             }
  80.             /**
  81.              * Create the URL
  82.              */
  83.             var url = utils.appRestUrl + "mocs/search?projectId="+this.projectId;
  84.            
  85.             for(var key in criteria){
  86.                 url+="&" + key+"="+criteria[key];
  87.             }
  88.            
  89.             /**
  90.              * Send request
  91.              */
  92.             xhr.get({
  93.                 url:url,
  94.                 handleAs:"json",
  95.                 load:function(results){
  96.                     _this.resultsGrid.reset(results);
  97.                 },
  98.                 error:function(error, ioargs){
  99.                     utils.showError(ioargs.xhr.responseText);
  100.                 }
  101.             });
  102.         }, //_onSearch
  103.        
  104.         //...
  105.        
  106.     });
  107. });
Advertisement
Add Comment
Please, Sign In to add comment