Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define([
- "dojo/dom-style",
- "dojo/_base/declare",
- "dojo/_base/event",
- "dojo/on",
- "dijit/_TemplatedMixin",
- "dijit/_WidgetsInTemplateMixin",
- "dijit/_WidgetBase",
- "dojo/text!./templates/MocsSearchPanel.html",
- "dojo/_base/xhr",
- "lib/utils",
- "dijit/form/Button",
- "dijit/form/TextBox",
- "dojox/form/Manager",
- "widgets/grids/MocsGrid"
- ], function(domStyle, declare, Event, on, _TemplatedMixin, _WidgetsInTemplateMixin, _WidgetBase, template, xhr, utils){
- return declare("widgets.panels.MocsSearchPanel", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
- // Path to template
- templateString : template,
- // Properties
- allowNullSelection:false,
- clearOnSelect:true,
- projectId:0,
- // PostCreate
- postCreate:function(){
- /**
- * Call super
- */
- this.inherited(arguments);
- /**
- * Disable selection
- */
- this.disableSelection();
- /**
- * Connect the search form
- */
- if(null!=this.searchForm){
- this.searchForm.on("submit", dojo.hitch(this, "_onSearch"));
- }
- /**
- * Connect the buttons
- */
- on(this.selectBtn, "onClick", this, "_onSelect");
- on(this.resultsGrid, "onSelectionChanged", this, "_onSelectionChange");
- },
- /**
- * Called when the search is clicked.
- */
- _onSearch:function(event){
- // Stop the submit event
- Event.stop(event);
- // Create the variables
- var _this = this,
- criteria = this.searchForm.gatherFormValues(),
- criteriaAreValids = false;
- /**
- * Check the project id
- */
- if(null == this.projectId){
- utils.showError("Invalid project. Please reload the page.");
- return false;
- }
- /**
- * Clear the results grid
- */
- this.resultsGrid.reset();
- /**
- * Check the criteria
- */
- for(var key in criteria){
- if(criteria[key]!=null && criteria[key].length>=3) criteriaAreValids = true;
- }
- if(!criteriaAreValids){
- utils.showError("Almost one criterion must have 3 caracters or more.");
- return false;
- }
- /**
- * Create the URL
- */
- var url = utils.appRestUrl + "mocs/search?projectId="+this.projectId;
- for(var key in criteria){
- url+="&" + key+"="+criteria[key];
- }
- /**
- * Send request
- */
- xhr.get({
- url:url,
- handleAs:"json",
- load:function(results){
- _this.resultsGrid.reset(results);
- },
- error:function(error, ioargs){
- utils.showError(ioargs.xhr.responseText);
- }
- });
- }, //_onSearch
- //...
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment