ProxyConnectorRulesViewModel=function(proxyConnectorRules,proxyConnectors){
var self=this;
- this.proxyConnectorRules=ko.observableArray(proxyConnectorRules?proxyConnectorRules:[]);
+ this.proxyConnectorRules=ko.observableArray(proxyConnectorRules);
this.proxyConnectors=proxyConnectors;
+ // FIXME get that from a REST service
+ // FIXME i18n
+ this.ruleTypes=[new RuleType("WHITE_LIST"," white list"),new RuleType("BLACK_LIST"," black list")];
+
this.displayGrid=function(){
var mainContent = $("#main-content");
data: self.proxyConnectorRules,
pageSize: 5,
gridUpdateCallBack: function(){
- $("#main-content" ).find("#proxy-connectors-rules-view-tabsTable" ).find("[title]").tooltip();
+ //$("#main-content" ).find("#proxy-connectors-rules-view-tabsTable" ).find("[title]").tooltip();
}
});
- ko.applyBindings(self,mainContent.find("#proxy-connectors-rules-view-tabs-view").get(0));
+ ko.applyBindings(self,mainContent.find("#proxy-connector-rules-view").get(0));
removeSmallSpinnerImg();
-
mainContent.find("#proxy-connectors-rules-view-tabs").on('show', function (e) {
$.log("on show:"+$(e.target).attr("href"));
if ($(e.target).attr("href")=="#proxy-connector-rules-edit") {
ko.applyBindings(proxyConnectorRuleViewModel,mainContent.find("#proxy-connector-rules-edit" ).get(0));
activateProxyConnectorRulesEditTab();
}
+ });
+ }
+ addProxyConnectorRule=function(proxyConnectorRule){
+ $.log("addProxyConnectorRule");
+ self.saveProxyConnectorRule(proxyConnectorRule,"restServices/archivaServices/proxyConnectorRuleService/proxyConnectorRule");
+ }
+
+ this.saveProxyConnectorRule=function(proxyConnectorRule,url){
+ $.log("saveProxyConnectorRule:"+url);
+ $("#user-messages" ).html(mediumSpinnerImg());
+ $.ajax(url,
+ {
+ type: "POST",
+ contentType: 'application/json',
+ data: ko.toJSON(proxyConnectorRule),
+ dataType: 'json',
+ success: function(data) {
+ $.log("save proxyConnectorRule pattern:"+proxyConnectorRule.pattern());
+ var message=$.i18n.prop(self.update?'proxy-connector-rule.updated':'proxy-connector-rule.added',proxyConnectorRule.pattern());
+ displaySuccessMessage(message);
+ proxyConnectorRule.modified(false);
+ self.proxyConnectorRules.push(proxyConnectorRule);
+ activateProxyConnectorRulesGridTab();
+ },
+ error: function(data) {
+ var res = $.parseJSON(data.responseText);
+ displayRestError(res);
+ },
+ complete:function(data){
+ removeMediumSpinnerImg("#user-messages");
+ }
+ }
+ );
+ }
+ updateProxyConnectorRule=function(proxyConnectorRule){
+ $.log("updateProxyConnectorRule");
+ self.saveProxyConnectorRule(proxyConnectorRule,"restServices/archivaServices/proxyConnectorRuleService/updateProxyConnectorRule");
+ }
+
+ removeProxyConnectorRule=function(proxyConnectorRule){
+
+ //FIXME modal dialog to confirm
+
+ $("#user-messages" ).html(mediumSpinnerImg());
+ $.ajax("restServices/archivaServices/proxyConnectorRuleService/deleteProxyConnectorRule",
+ {
+ type:"POST",
+ contentType: 'application/json',
+ data: ko.toJSON(proxyConnectorRule),
+ dataType: 'json',
+ success:function(data){
+ var message=$.i18n.prop('proxy-connector-rule.deleted',proxyConnectorRule.pattern());
+ displaySuccessMessage(message);
+ },
+ error: function(data) {
+ var res = $.parseJSON(data.responseText);
+ displayRestError(res);
+ },
+ complete:function(data){
+ removeMediumSpinnerImg("#user-messages");
+ }
+ }
+ );
+ }
+
+ editProxyConnectorRule=function(proxyConnectorRule){
+ var proxyConnectorRuleViewModel=new ProxyConnectorRuleViewModel(proxyConnectorRule,self,true);
+ ko.applyBindings(proxyConnectorRuleViewModel,$("#main-content").find("#proxy-connector-rules-edit" ).get(0));
+ activateProxyConnectorRulesEditTab();
- });
}
+
}
ProxyConnectorRuleViewModel=function(proxyConnectorRule,proxyConnectorRulesViewModel,update){
this.update=update;
proxyConnectorMoved=function(arg){
+ $.log("repositoryMoved:"+arg.sourceIndex+" to " + arg.targetIndex);
+ }
+ saveProxyConnectorRule=function(){
+ $.log("pattern:"+self.proxyConnectorRule.pattern());
+ $.log("proxyConnectorRuleType:"+proxyConnectorRule.proxyConnectorRuleType());
+ $.log("proxyConnectors:"+proxyConnectorRule.proxyConnectors().length);
+ self.proxyConnectorRulesViewModel.saveProxyConnectorRule(self.proxyConnectorRule)
}
}
screenChange();
var mainContent = $("#main-content");
mainContent.html($("#proxyConnectorsRulesMain").tmpl());
- mainContent.append(smallSpinnerImg());
+ $("#user-messages").html(mediumSpinnerImg());
loadAllProxyConnectors(function(data){
var proxyConnectors = mapProxyConnectors(data);
var proxyConnectorRulesViewModel = new ProxyConnectorRulesViewModel(proxyConnectorRules,proxyConnectors);
proxyConnectorRulesViewModel.displayGrid();
activateProxyConnectorRulesGridTab();
+ },
+ complete: function(data){
+ removeMediumSpinnerImg("#user-messages");
}
});
if (data==null){
return null;
}
- return new ProxyConnector(data.pattern, data.proxyConnectorRuleType, mapProxyConnectors(data.proxyConnectors));
+ return new ProxyConnectorRule(data.pattern, data.proxyConnectorRuleType, mapProxyConnectors(data.proxyConnectors));
}
mapProxyConnectorRules=function(data){
activateProxyConnectorRulesGridTab=function(){
var mainContent = $("#main-content");
mainContent.find("#proxy-connectors-rules-view-tabs-content div[class*='tab-pane']").removeClass("active");
- mainContent.find("#proxy-connectors-rules-view-tabs > li").removeClass("active");
+ mainContent.find("#proxy-connectors-rules-view-tabs li").removeClass("active");
- mainContent.find("#repository-groups-view").addClass("active");
+ mainContent.find("#proxy-connector-rules-view").addClass("active");
mainContent.find("#proxy-connectors-rules-view-tabs-li-grid").addClass("active");
mainContent.find("#proxy-connectors-rules-view-tabs-a-edit").html($.i18n.prop("add"));
mainContent.find("#proxy-connectors-rules-view-tabs-edit").addClass("active");
}
+ RuleType=function(type,label){
+ this.type=type;
+ this.label=label;
+ }
});
<ul id="proxy-connectors-rules-view-tabs" class="nav nav-tabs">
<li id="proxy-connectors-rules-view-tabs-li-grid" class="active">
- <a data-toggle="tab" href="#proxy-connector-rules-view" id="proxy-connectors-rules-view-tabs-a-network-proxies-grid">${$.i18n.prop('proxy-connectors-rules.grid.tab.title')}</a>
+ <a data-toggle="tab" href="#proxy-connector-rules-view" id="proxy-connectors-rules-view-tabs-a-grid">${$.i18n.prop('proxy-connectors-rules.grid.tab.title')}</a>
</li>
<li id="proxy-connectors-rules-view-tabs-li-edit">
<a data-toggle="tab" href="#proxy-connector-rules-edit" id="proxy-connectors-rules-view-tabs-a-edit">${$.i18n.prop('add')}</a>
</li>
</ul>
<div id="proxy-connectors-rules-view-tabs-content" class="tab-content">
- <div id="proxy-connectors-rules-view-tabs-view" class="tab-pane active">
+ <div id="proxy-connector-rules-view" class="tab-pane active">
<div id="proxy-connectors-rules-view-tabs-bulk-save-btn" data-bind='template:{name:"proxy-connectors-rules-view-tabs-bulk-save-tmpl"}'></div>
<table class="table table-striped table-bordered" id="proxy-connectors-rules-view-tabsTable"
data-bind="simpleGrid: gridViewModel,simpleGridTemplate:'ko-proxy-connectors-rules-grid',pageLinksId:'proxy-connectors-rules-pagination'">
</thead>
<tbody>
{{each(i, row) itemsOnCurrentPage()}}
- <tr data-bind="css:{ 'modified': row.modified()}">
- <td>${row.pattern()}</td>
- <td>${row.proxyConnectorRuleType()}</td>
- <td>connector</td>
- <td>edit</td>
- <td>delete</td>
- <td>save</td>
- </tr>
+ <tr data-bind="css:{ 'modified': row.modified()}">
+ <td>${row.pattern()}</td>
+ <td>${row.proxyConnectorRuleType()}</td>
+ <td>
+ <ul>
+ {{each(j,proxyConnector) row.proxyConnectors()}}
+ <li>${proxyConnector.sourceRepoId()} <-> ${proxyConnector.targetRepoId()}</li>
+ {{/each}}
+ </ul>
+ </td>
+ <td>
+ <a href="#" data-bind="click: function(){ editProxyConnectorRule(row) }">
+ <span class="btn btn-primary">
+ <i class="icon-pencil icon-white"/>
+ </span>
+ </a>
+ </td>
+ <td>
+ <a href="#" data-bind="click: function(){ removeProxyConnectorRule(row) }">
+ <span class="btn btn-danger">
+ <i class="icon-trash icon-white"/>
+ </span>
+ </a>
+ </td>
+ <td>
+ {{if row.modified()}}
+ <a href="#" class="btn btn-warning" data-bind="click: function(){ updateProxyConnectorRule(row) }">${$.i18n.prop('save')}</a>
+ {{/if}}
+ </td>
+ </tr>
{{/each}}
</tbody>
</script>
<div class="dotted span8">
<blockquote>
${proxyConnectorRule.pattern()}
+ <br/>
+ ${proxyConnectorRule.proxyConnectorRuleType()}
</blockquote>
</div>
{{else}}
data-bind="value:proxyConnectorRule.pattern,css:{'uneditable-input': update},readonly:update"/>
</div>
</div>
+ <div class="control-group">
+ <label class="control-label" for="layout">${$.i18n.prop('type')}</label>
+ <div class="controls">
+ <select id="proxy-connector-rule-pattern-type"
+ data-bind="options: proxyConnectorRulesViewModel.ruleTypes,optionsText: 'label',optionsValue:'type',value: proxyConnectorRule.proxyConnectorRuleType"/>
+ </div>
+ </div>
</fieldset>
</form>
</div>
{{/if}}
{{if proxyConnectorRule.modified()}}
<div class="span3">
- <a href="#" class="btn btn-warning" data-bind="click: function(){saveRepositoryGroup(repositoryGroup)}">${$.i18n.prop('save')}</a>
+ <a href="#" class="btn btn-warning" data-bind="click: function(){addProxyConnectorRule(proxyConnectorRule)}">${$.i18n.prop('save')}</a>
</div>
<br/>
{{/if}}