2011-08-24 23:41:39 -03:00
|
|
|
/*
|
|
|
|
* Copyright [2011] [wisemapping]
|
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mindplot.DesignerModel = new Class({
|
2012-07-06 21:21:56 -03:00
|
|
|
Implements:[Events],
|
|
|
|
initialize:function (options) {
|
2011-08-24 23:41:39 -03:00
|
|
|
this._zoom = options.zoom;
|
|
|
|
this._topics = [];
|
2012-07-06 21:21:56 -03:00
|
|
|
this._relationships = [];
|
2011-08-24 23:41:39 -03:00
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
getZoom:function () {
|
2011-08-24 23:41:39 -03:00
|
|
|
return this._zoom;
|
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
setZoom:function (zoom) {
|
2011-08-24 23:41:39 -03:00
|
|
|
this._zoom = zoom;
|
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
getTopics:function () {
|
2011-08-24 23:41:39 -03:00
|
|
|
return this._topics;
|
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
getRelationships:function () {
|
|
|
|
return this._relationships;
|
|
|
|
},
|
|
|
|
|
|
|
|
getCentralTopic:function () {
|
2011-08-24 23:41:39 -03:00
|
|
|
var topics = this.getTopics();
|
|
|
|
return topics[0];
|
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
filterSelectedTopics:function () {
|
2011-08-24 23:41:39 -03:00
|
|
|
var result = [];
|
|
|
|
for (var i = 0; i < this._topics.length; i++) {
|
|
|
|
if (this._topics[i].isOnFocus()) {
|
|
|
|
result.push(this._topics[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
filterSelectedRelationships:function () {
|
2011-08-24 23:41:39 -03:00
|
|
|
var result = [];
|
2012-07-06 21:21:56 -03:00
|
|
|
for (var i = 0; i < this._relationships.length; i++) {
|
|
|
|
if (this._relationships[i].isOnFocus()) {
|
|
|
|
result.push(this._relationships[i]);
|
2011-08-24 23:41:39 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
getEntities:function () {
|
2011-08-24 23:41:39 -03:00
|
|
|
var result = [].append(this._topics);
|
2012-07-06 21:21:56 -03:00
|
|
|
result.append(this._relationships);
|
2011-08-24 23:41:39 -03:00
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
removeTopic:function (topic) {
|
2011-08-24 23:41:39 -03:00
|
|
|
$assert(topic, "topic can not be null");
|
|
|
|
this._topics.erase(topic);
|
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
removeRelationship:function (rel) {
|
|
|
|
$assert(rel, "rel can not be null");
|
|
|
|
this._relationships.erase(rel);
|
|
|
|
},
|
|
|
|
|
|
|
|
addTopic:function (topic) {
|
2011-08-24 23:41:39 -03:00
|
|
|
$assert(topic, "topic can not be null");
|
|
|
|
this._topics.push(topic);
|
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
addRelationship:function (rel) {
|
2011-10-09 17:59:16 -03:00
|
|
|
$assert(rel, "rel can not be null");
|
2012-07-06 21:21:56 -03:00
|
|
|
this._relationships.push(rel);
|
2011-10-09 17:59:16 -03:00
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
filterTopicsIds:function (validate, errorMsg) {
|
2011-08-24 23:41:39 -03:00
|
|
|
var result = [];
|
|
|
|
var topics = this.filterSelectedTopics();
|
|
|
|
|
2011-10-04 01:16:29 -03:00
|
|
|
|
|
|
|
var isValid = true;
|
|
|
|
for (var i = 0; i < topics.length; i++) {
|
|
|
|
var selectedNode = topics[i];
|
|
|
|
if ($defined(validate)) {
|
|
|
|
isValid = validate(selectedNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add node only if it's valid.
|
|
|
|
if (isValid) {
|
|
|
|
result.push(selectedNode.getId());
|
|
|
|
} else {
|
2011-11-28 17:11:02 -03:00
|
|
|
$notify(errorMsg);
|
2011-08-24 23:41:39 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2011-08-25 22:08:39 -03:00
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
selectedTopic:function () {
|
2011-08-25 22:08:39 -03:00
|
|
|
var topics = this.filterSelectedTopics();
|
|
|
|
return (topics.length > 0) ? topics[0] : null;
|
2012-01-11 18:41:09 -03:00
|
|
|
},
|
|
|
|
|
2012-07-06 21:21:56 -03:00
|
|
|
findTopicById:function (id) {
|
2012-01-11 18:41:09 -03:00
|
|
|
var result = null;
|
|
|
|
for (var i = 0; i < this._topics.length; i++) {
|
|
|
|
var topic = this._topics[i];
|
2012-07-06 21:21:56 -03:00
|
|
|
if (topic.getId() == id) {
|
2012-01-11 18:41:09 -03:00
|
|
|
result = topic;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2011-08-24 23:41:39 -03:00
|
|
|
|
2012-01-11 18:41:09 -03:00
|
|
|
}
|
2011-08-24 23:41:39 -03:00
|
|
|
});
|