[TIC-Web] source clean up
[archive/20170607/tools/tic.git] / public / src / js / model / ImageModel.js
1 define([
2     'jquery',
3     'lodash',
4     'js/util',
5     'js/logger'
6 ], function (
7     $,
8     _,
9     Util,
10     Logger
11 ) {
12     'use strict';
13
14     var logger = Logger('model/ImageModel.js');
15
16     // config
17     var AppConfig = null;
18
19     // define the downloadable status
20     var DOWNLOADABLE_STATUS = 'DONE';
21     // define the default status
22     var DEFAULT_STATUS = 'READY';
23
24     // set the config information for the app
25     Util.getAppConfig().then(function (data) {
26         AppConfig = data;
27     });
28
29     var ImageModel = function (paramObj) {
30         this.imageId;
31         this.imageName;
32         this.imageSize;
33         this.imageUptime;
34         this.imageStatus;
35
36         this.imageJobId;
37         this.imageJobPath;
38
39         this.imageHasKsFile;
40         this.imageIsDownload;//{boolean}
41
42         // for the href on a tag
43         this.jobAbsPath;
44         this.jobAbsImagePath;
45         this.jobAbsKsPath;
46         this.jobAbsLogPath;
47
48         this.init(paramObj);
49
50         return this;
51     };
52
53     ImageModel.prototype.init = function (obj) {
54         logger.info('init: ' + JSON.stringify(obj));
55
56         this.setImageId(obj.image_id);
57         this.setImageName(obj.image_name);
58         this.setImageSize(obj.image_size);
59         this.setImageUptime(obj.image_uptime);
60         this.setImageStatus(obj.image_status);
61
62         this.setImageJobId(obj.image_job_id);
63
64         this.setImageHasKsFile(obj.image_hasksfile);
65         this.setImageIsDownload(obj.image_status);
66
67         this.setJobAbsPath();
68         this.setJobAbsImagePath();
69         this.setJobAbsKsPath();
70         this.setJobAbsLogPath();
71     };
72
73     ImageModel.prototype.getJobAbsLogPath = function getJobAbsLogPath () {
74         return this.jobAbsLogPath;
75     };
76
77     ImageModel.prototype.setJobAbsLogPath = function setJobAbsLogPath () {
78         this.jobAbsLogPath = this.getJobAbsPath() + AppConfig.TIC_WEB.LOG_FILE_NAME;
79     };
80
81     ImageModel.prototype.getJobAbsKsPath = function getJobAbsKsPath (value) {
82         return this.jobAbsKsPath = value;
83     };
84
85     ImageModel.prototype.setJobAbsKsPath = function setJobAbsKsPath (value) {
86         this.jobAbsKsPath = value || this.getJobAbsPath() + AppConfig.TIC_WEB.KS_FILE_NAME;
87     };
88
89     ImageModel.prototype.getJobAbsImagePath = function getJobAbsImagePath () {
90         return this.jobAbsImagePath;
91     };
92
93     ImageModel.prototype.setJobAbsImagePath = function setJobAbsImagePath (value) {
94         this.jobAbsImagePath = value || this.getJobAbsPath() + this.getImageName();
95     };
96
97     ImageModel.prototype.getJobAbsPath = function getJobAbsPath (value) {
98         return this.jobAbsPath;
99     };
100
101     ImageModel.prototype.setJobAbsPath = function setJobAbsPath (value) {
102         this.jobAbsPath = value || AppConfig.TIC_WEB.PATH_ABSTRACT + this.getImageJobId() + '/';
103     };
104
105     ImageModel.prototype.getImageIsDownload = function getImageIsDownload () {
106         return this.imageIsDownload;
107     };
108
109     ImageModel.prototype.setImageIsDownload = function setImageIsDownload (value) {
110         var status, isDownloadable;
111
112         isDownloadable = false;
113         status = value || this.getImageStatus();
114
115         if (status === DOWNLOADABLE_STATUS) {
116             isDownloadable = true;
117         }
118         this.imageIsDownload = isDownloadable;
119     };
120
121     ImageModel.prototype.getImageHasKsFile = function getImageHasKsFile () {
122         return this.imageHasKsFile;
123     };
124
125     ImageModel.prototype.setImageHasKsFile = function setImageHasKsFile (value) {
126         this.imageHasKsFile = value || false;
127     };
128
129     ImageModel.prototype.getImageJobId = function getImageJobId (value) {
130         return this.imageJobId;
131     };
132
133     ImageModel.prototype.setImageJobId = function setImageJobId (value) {
134         this.imageJobId = value || 0;
135     };
136
137     ImageModel.prototype.getImageStatus = function getImageStatus () {
138         return this.imageStatus;
139     };
140
141     ImageModel.prototype.setImageStatus = function setImageStatus (value) {
142         this.imageStatus = value || DEFAULT_STATUS;
143     };
144
145     ImageModel.prototype.getImageUptime = function getImageUptime (value) {
146         return this.imageUptime;
147     };
148
149     ImageModel.prototype.setImageUptime = function setImageUptime (value) {
150         this.imageUptime = value || '';
151     };
152
153     ImageModel.prototype.getImageSize = function getImageSize () {
154         return this.imageSize;
155     };
156
157     ImageModel.prototype.setImageSize = function setImageSize (value) {
158         this.imageSize = value ? Util.bytesToSize(value) : '0KB';
159     };
160
161     ImageModel.prototype.getImageName = function getImageName () {
162         return this.imageName;
163     };
164
165     ImageModel.prototype.setImageName = function setImageName (value) {
166         this.imageName = value || '-';
167     };
168
169     ImageModel.prototype.getImageId = function getImageId () {
170         return this.imageId;
171     };
172
173     ImageModel.prototype.setImageId = function setImageId (value) {
174         this.imageId = value;
175     };
176
177     return ImageModel;
178 });