      1 /*
      2  *  Copyright (C) 2008-2009 WaveMaker Software, Inc.
      3  *
      4  *  This file is part of the WaveMaker Client Runtime.
      5  *
      6  *  Licensed under the Apache License, Version 2.0 (the "License");
      7  *  you may not use this file except in compliance with the License.
      8  *  You may obtain a copy of the License at
      9  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  *  Unless required by applicable law or agreed to in writing, software
     13  *  distributed under the License is distributed on an "AS IS" BASIS,
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  *  See the License for the specific language governing permissions and
     16  *  limitations under the License.
     17  */
     18 dojo.provide("wm.base.components.ServiceVariable");
     19 dojo.require("wm.base.components.Variable");
     20 dojo.require("wm.base.components.ServiceCall");
     21
     22
     23 //===========================================================================
     24 // Main service calling class: calls services with input data and returns data
     25 //===========================================================================
     26 /**
     27 	Main service calling class: calls services with input data and returns data
     28 	@name wm.ServiceVariable
     29 	@class
     30 	@extends wm.Variable
     31 	@extends wm.ServiceCall
     32 */
     33 dojo.declare("wm.ServiceVariable", [wm.Variable, wm.ServiceCall], {
     34 	total: 0,
     35 	_page: 0,
     36 	processResult: function(inResult) {
     37 		this.setData(inResult);
     38 		this.inherited(arguments);
     39 	},
     40 	getTotal: function() {
     41 		return this.total || this.getCount();
     42 	},
     43 	getPageCount: function() {
     44 		return Math.ceil(this.getTotal() / (this.getCount() || 1));
     45 	},
     46 	setPage: function(inPage) {
     47 		this._page = Math.max(0, Math.min(this.getPageCount() - 1, inPage));
     48 		this.firstRow = this._page * this.maxResults;
     49 		this.update();
     50 	},
     51 	getPage: function() {
     52 		return this._page;
     53 	},
     54 	setFirstPage: function() {
     55 		this.setPage(0);
     56 	},
     57 	setPreviousPage: function() {
     58 		this.setPage(this._page-1);
     59 	},
     60 	setNextPage: function() {
     61 		this.setPage(this._page+1);
     62 	},
     63 	setLastPage: function() {
     64 		this.setPage(this.getPageCount());
     65 	},
     66 	operationChanged: function() {
     67 		this.inherited(arguments);
     68 		// output has named type matching operation returnType
     69 		var op = this._operationInfo;
     70 		if (op)
     71 			this.setType(op.returnType);
     72 	}
     73 });
     74
     75 wm.Object.extendSchema(wm.ServiceVariable, {
     76 	operation: { group: "common", order: 24},
     77 	clearInput: { group: "operation", order: 30},
     78 	input: { ignore: 1 , writeonly: 1, componentonly: 1, categoryParent: "Properties", categoryProps: {component: "input", bindToComponent: true, inspector: "Data"}},
     79 	service: {group: "common", order: 23 },
     80 	autoUpdate: {group: "common", order: 25},
     81 	startUpdate: {group: "common", order: 26},
     82 	updateNow: { group: "operation", order: 10},
     83 	queue: { group: "operation", order: 20},
     84 	json: {ignore: 1},
     85 	listType: {ignore: 1},
     86 	isList: {ignore: 1},
     87 	// binding inherited from Variable, keep it and write it but don't show it
     88 	// potentially needed for source bindings.
     89 	binding: {ignore: 1, writeonly: 1},
     90 	type: { ignore: 1 },
     91 	dataSet: { ignore: 1, defaultBindTarget: 1, isObject: true, type: "any"},
     92 	total: {ignore: 1}
     93 });
     94
     95
     96 wm.ServiceVariable.description = "Data from a service.";
     97
     98 /**#@+ @design */
     99 wm.ServiceVariable.extend({
    100 	/** @lends wm.ServiceVariable.prototype */
    101 });
    102 /**#@- @design *