// Connector class
Mjs.Models.Connector = function(params) {
this.attrs = {};
this.attrs.type = params.type; // branch or path
this.attrs.name = params.name;
this.attrs.direction = params.direction;
// favor overrides
this.attrs.img = params.img || this.attrs.type + "_conn";
this.attrs.id = params.id || (this.attrs.type +
Mjs.Models.Connector._counter++);
this.attrs.sourceNumCL = params.sourceNumCL; // 0 means something
this.attrs.targetNumCL = params.targetNumCL; // 0 means something
this.attrs.source = params.source;
this.attrs.target = params.target;
this.attrs.latestSource = params.latestSource;
this.attrs.latestTarget = params.latestTarget;
this._createGettersAndSetters();
};
Mjs.Models.Connector.prototype = {
_createGettersAndSetters: function() {
var me = this;
var creator = function(key, value) {
Object.defineProperty(me, key, {
get: function() {
return value;
},
set: function(val) {
var notify = false;
var prevVal = me.attrs[key];
me.attrs[key] = val;
if (prevVal != val) {
Mjs.notify("Mjs.Models.Connector:change: " + attr,
{newValue : val});
};
},
});
};
for(attr in this.attrs) {
creator(attr, this.attrs[attr]);
};
},
htmlTag : function() {
var conn_tag = "<div class='c" +
"' id='" + this.id + "'>" +
"<div id='" + this.img + "' title='" + this.name + "'></div>" +
"<div class='cex'></div></div>";
return conn_tag;
},
_exportTypeMapping : {
'branch' : 'branchSpecMapping',
'path' : 'depotPathMapping'
},
// required for export
toXml : function() {
var type = this.type;
var xmlTagBuffer = ['<',
this._exportTypeMapping[type],
' id="' ,
this.id,
'" name="',
this.name,
'" direction="',
this.direction,
'" joints="',
this.joints,
'" latestSource="',
this.latestSource,
'" latestTarget="',
this.latestTarget,
'" source="',
this.source,
'" sourceAnchor="',
this.sourceAnchor,
'" sourceChanges="',
this.sourceChanges,
'" sourceCount="',
this.sourceCount,
'" target="',
this.target,
'" targetAnchor="',
this.targetAnchor,
'" targetChanges="',
this.targetChanges,
'" targetCount="',
this.targetCount];
if (type == 'path') {
xmlTagBuffer.push('" sourcePath="');
xmlTagBuffer.push(this.sourcePath);
xmlTagBuffer.push('" targetPath="');
xmlTagBuffer.push(this.targetPath);
}
xmlTagBuffer.push('"/>');
return xmlTagBuffer.join('');
},
domId : function() {
return this.id;
},
constructor: Mjs.Models.Connector
};
Mjs.Models.Connector._counter = 0;
// ConnectorCollection class
Mjs.Models.ConnectorCollection = function() {
this._resetInternals();
this.MESSAGE_CONNECTOR_CREATED = "ConnectorCollection:ConnectorCreated";
this.MESSAGE_CONNECTOR_DELETED = "ConnectorCollection:ConnectorDeleted";
};
Mjs.Models.ConnectorCollection.prototype = {
add: function(connectorParams) {
var connector = new Mjs.Models.Connector(connectorParams);
this._collection[connector.id] = connector;
Mjs.notify.publish(this.MESSAGE_CONNECTOR_CREATED,
{connector: connector});
},
remove: function(model) {
this.removeById(model.id);
},
removeById: function(id) {
var connector = this._collection[id];
delete this._collection[id];
Mjs.notify.publish(this.MESSAGE_CONNECTOR_DELETED,
{connector: connector});
},
removeAll: function() {
var key;
for (key in this._collection) {
this.removeById(key);
}
},
toArray: function() {
var key, arr = [];
for (key in this._collection) {
arr.push(this._collection[key]);
}
return arr;
},
_resetInternals : function() {
this._collection = {};
},
constructor: Mjs.Models.ConnectorCollection
};
// Codeline Class
// Info needed for Eclipse xml export
// height: 0, //"41"
// id: 0, // codeline1, codeline2
// name: "Not specified", // "Chris Main"
// type: "Not specified", // development, main, release
//
// width: 0, // "121"
// x: 0, // "265"
// y: 0, // "395
Mjs.Models.Codeline = function(params) {
this.attrs = {};
this.attrs.type = params.type;
this.attrs.name = params.name;
this.attrs.img = params.img || (this.attrs.type + "_img");
console.log('params.id = ' + params.id);
this.attrs.id = params.id || (this.attrs.type + Mjs.Models.Codeline._counter++);
this.attrs.x = params.x;
this.attrs.y = params.y;
Mjs.Models.Connector.prototype._createGettersAndSetters.call(this);
};
Mjs.Models.Codeline.prototype = {
htmlTag :function() {
var code_tag = "<div class='w " + this.type +
"' id=" + this.id + ">" +
"<div id=" + this.img + "></div>" +
this.name +
"<div class='ex'></div>" +
"<div class='ep' title='Drag to another codeline to establish connection'></div></div>";
return code_tag;
},
// required for export
toXml : function() {
var jEl = $('#' +this.id);
var pos = jEl.position();
var width = jEl.width();
var height = jEl.height();
var xmlTagBuffer = ['<branch id="' ,
this.id,
'" type="',
this.type,
'" name="',
this.name,
'" width="',
width,
'" height="',
height,
'" x="',
pos.left,
'" y="',
pos.top,
'"/>'];
return xmlTagBuffer.join('');
},
domId : function() {
return this.id;
},
constructor: Mjs.Models.Codeline
};
// counter for the unique ids we need in the Codeline class
Mjs.Models.Codeline._counter = 0;
// CodelineCollection class
Mjs.Models.CodelineCollection = function() {
this._resetInternals();
this.MESSAGE_CODELINE_CREATED = "CodelineCollection:CodelineCreated";
this.MESSAGE_CODELINE_DELETED = "CodelineCollection:CodelineDeleted";
};
Mjs.Models.CodelineCollection.prototype = {
add: function(codelineType, codeName) {
var codeline = new Mjs.Models.Codeline(codelineType, codeName);
this._collection[codeline.id] = codeline;
Mjs.notify.publish(this.MESSAGE_CODELINE_CREATED,
{codeline: codeline});
},
// Will need some kind of a remove function
// for when we delete codelines
remove: function(model) {
this.removeById(model.id);
},
removeById: function(id) {
var codeline = this._collection[id];
delete this._collection[id];
Mjs.notify.publish(this.MESSAGE_CODELINE_DELETED,
{codeline: codeline});
},
removeAll: function() {
var key;
for (key in this._collection) {
this.removeById(key);
}
},
toArray: function() {
var key, arr = [];
for (key in this._collection) {
arr.push(this._collection[key]);
}
return arr;
},
_resetInternals : function() {
this._collection = {};
},
constructor : Mjs.Models.CodelineCollection
};