[TIC-Web] Apply generic resource pooling
[archive/20170607/tools/tic.git] / public / src / js / widget / ImageItem.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('widget/ImageItem.js');
15
16     // config
17     var AppConfig = null;
18
19     var strItem = [
20         '<li class="list-group-item image-item">',
21             '<div class="image-item-title">',
22                 '<div class="image-list-name" title="<%= jobId %>_<%= imageFileName %>">#<%= jobId %>.  <%= imageFileName %></div>',
23                 '<div class="image-list-name-btndownload"><a class="image-list-btndownload" href="<%= imagePath %>" title="<%= imageFileName %>" date-name="<%= imageFileName %>">Download</a></div>',
24                 '<div class="image-list-name-btndownload"><a class="image-list-btndownload <%= classJobKsPath %>" href="<%= ksPath %>" title="<%= ksFileName %>" date-name="<%= ksFileName %>">KS</a></div>',
25                 '<div class="image-list-name-btndownload"><a class="image-list-btndownload btnbiglog" data-link="<%= logPath %>" data-jobid="<%= jobId %>" title="Log" date-name="<%= logFileName %>">Log</a></div>',
26             '</div>',
27             '<div class="image-item-info">',
28                 '<p class="image-list-detail"><b>Job ID:</b> <%= jobId %></p>',
29                 '<p class="image-list-detail"><b>Name:</b> <%= imageFileName %></p>',
30                 '<p class="image-list-detail"><b>Size:</b> <%= fileSize %></p>',
31                 '<p class="image-list-detail"><b>Arch:</b> <%= fileArch %></p>',
32                 '<p class="image-list-detail"><b>KS:</b> <%= ksFileName %></p>',
33                 '<p class="image-list-detail"><b>Updated:</b> <%= fileTime %></p>',
34             '</div>',
35         '</li>'
36     ];
37
38     // set the config information for the app
39     Util.getAppConfig()
40     .then(function (data) {
41         AppConfig = data;
42     });
43
44
45     var ImageItem = function (modelObj) {
46         this.model = modelObj;
47         this.template;
48
49         this.init(this.model);
50
51         return this;
52     };
53
54     ImageItem.prototype.init = function () {
55         this.setTemplate(this.model);
56     };
57
58     ImageItem.prototype.getTemplate = function getTemplate() {
59         return this.template;
60     };
61
62     ImageItem.prototype.setTemplate = function setTemplate(item) {
63         this.template = _.template(_.join(strItem, ''))({
64             jobId: item.getImageJobId(),
65             fileSize: item.getImageSize(),
66             fileTime: item.getImageUptime(),
67             imageFileName: item.getImageName(),
68             ksFileName: item.getImageKs() || 'None',
69             logFileName: AppConfig.TIC_WEB.LOG_FILE_NAME,
70             imagePath: item.getJobAbsImagePath(),
71             classJobKsPath: item.getImageHasKsFile() === '0' ? 'btnnotactive' : '',
72             ksPath: item.getJobAbsKsPath(),
73             logPath: item.getJobAbsLogPath(),
74             fileArch: item.getImageArch()
75         });
76     };
77
78     return ImageItem;
79 });