aboutsummaryrefslogtreecommitdiffstats
path: root/view/theme/redbasic/tpl/admin_plugins.tpl
blob: fd5ae7d5e2b9a8b55180a64d2561570318280995 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<div class="generic-content-wrapper">
	<div class="section-title-wrapper">
		{{if $allowManageRepos}}
		<div class="pull-right">
			<button class="btn btn-success btn-sm" onclick="openClose('form');">{{$managerepos}}</button>
		</div>
		{{/if}}
		<h2 id="title">{{$title}} - {{$page}}</h2>
		<div class="clear"></div>
	</div>
	<div id="form" class="section-content-tools-wrapper"{{if !$expandform}} style="display:none;"{{/if}}>
         
        <div class="clear"></div>
        <div class="section-title-wrapper" style="margin-top: 20px;">
          <h2>{{$installedtitle}}</h2>
          <div class="clear"></div>
        </div>
      <div class="table-responsive section-content-tools-wrapper">
      <table class="table table-responsive table-striped table-hover">
        {{foreach $addonrepos as $repo}}
        <tr>
            <td style="width: 70%;">
				<span class="pull-left">{{$repo.name}}</span><span id="update-message-{{$repo.name}}" style="margin-left: 20px;"></span>
            </td>
            <td style="width: 15%;">
              <button class="btn btn-sm btn-primary pull-right" style="margin-left: 10px; margin-right: 10px;" onclick="updateAddonRepo('{{$repo.name}}'); return false;"><i class='fa fa-download'></i>&nbsp;{{$repoUpdateButton}}</button>
            </td>
            <td style="width: 15%;">
              <button class="btn btn-sm btn-danger pull-right" style="margin-left: 10px; margin-right: 0px;" onclick="removeAddonRepo('{{$repo.name}}'); return false;"><i class='fa fa-trash-o'></i>&nbsp;{{$repoRemoveButton}}</button>
            </td>
        <div class="clear"></div>
        </td></tr>
        {{/foreach}}
        </table>
      </div>
      <div class="clear"></div>
         <div class="section-title-wrapper">
          <h2>{{$addnewrepotitle}}</h2>
          <div class="clear"></div>
        </div>
		{{$form}}
    </div>
      <div class="clear"></div>
    <div id="chat-rotator-wrapper" class="center-block">
        <div id="chat-rotator"></div>
    </div>
    <div class="clear"></div>
	<div class="section-content-wrapper-np">
      {{foreach $plugins as $p}}
      <div class="section-content-tools-wrapper" id="pluginslist">		
		<div class="contact-info plugin {{$p.1}}">
            {{if ! $p.2.disabled}}				
            <a class='toggleplugin' href='{{$baseurl}}/admin/{{$function}}/{{$p.0}}?a=t&amp;t={{$form_security_token}}' title="{{if $p.1==on}}Disable{{else}}Enable{{/if}}" ><i class='fa {{if $p.1==on}}fa-check-square-o{{else}}fa-square-o{{/if}} admin-icons'></i></a>
            {{else}}
            <i class='fa fa-stop admin-icons'></i>
            {{/if}}
            <a href='{{$baseurl}}/admin/{{$function}}/{{$p.0}}'><span class='name'>{{$p.2.name}}</span></a> - <span class="version">{{$p.2.version}}</span>{{if $p.2.disabled}} {{$disabled}}{{/if}}
            {{if $p.2.experimental}} {{$experimental}} {{/if}}{{if $p.2.unsupported}} {{$unsupported}} {{/if}}

            <div class='desc'>{{$p.2.description}}</div>
		</div>
	</div>
    {{/foreach}}
      
	</div>
</div>
{{$newRepoModal}}
<script>
  
  // TODO: Implement a simple interface controller that reconfigures the modal dialog
  // for each action in a more organized way
  
  function adminPluginsAddRepo() {
      $("#generic-modal-ok-{{$newRepoModalID}}").removeClass('btn-success');
      $("#generic-modal-ok-{{$newRepoModalID}}").addClass('btn-primary');
      var repoURL = $('#id_repoURL').val();
      var repoName = $('#id_repoName').val();
      $('#chat-rotator').spin('tiny');
      $.post(
        "/admin/plugins/addrepo", {repoURL: repoURL, repoName: repoName}, 
            function(response) {
                $('#chat-rotator').spin(false);
                if (response.success) {
                  var modalBody = $('#generic-modal-body-{{$newRepoModalID}}');
                  modalBody.html('<div>'+response.repo.readme+'</div>');
                  modalBody.append('<h2>Repo Info</h2><p>Message: ' + response.message + '</p>');
                  modalBody.append('<h4>Branches</h4><p>'+JSON.stringify(response.repo.branches)+'</p>');
                  modalBody.append('<h4>Remotes</h4><p>'+JSON.stringify(response.repo.remote)+'</p>');
                  $('.modal-dialog').width('80%');
                  $("#generic-modal-ok-{{$newRepoModalID}}").off('click');
                  $("#generic-modal-ok-{{$newRepoModalID}}").click(function () {
                    installAddonRepo();
                  });
                  $('#generic-modal-{{$newRepoModalID}}').modal();
                } else {
                    window.console.log('Error adding repo :' + response['message']);
                }
                return false;
            },
        'json');
  }
  
  function installAddonRepo() {
      var repoURL = $('#id_repoURL').val();
      var repoName = $('#id_repoName').val();
      $.post(
        "/admin/plugins/installrepo", {repoURL: repoURL, repoName: repoName}, 
            function(response) {
                if (response.success) {
                  $('#generic-modal-title-{{$newRepoModalID}}').html('Addon repo installed');
                  var modalBody = $('#generic-modal-body-{{$newRepoModalID}}');
                  modalBody.html('<h2>Repo Info</h2><p>Message: ' + response.message + '</p>');
                  modalBody.append('<h4>Branches</h4><p>'+JSON.stringify(response.repo.branches)+'</p>');
                  modalBody.append('<h4>Remotes</h4><p>'+JSON.stringify(response.repo.remote)+'</p>');
                  $('.modal-dialog').width('80%');
                  //$("#generic-modal-cancel-{{$newRepoModalID}}").hide();
                  $("#generic-modal-ok-{{$newRepoModalID}}").html('OK');
                  $("#generic-modal-ok-{{$newRepoModalID}}").removeClass('btn-primary');
                  $("#generic-modal-ok-{{$newRepoModalID}}").addClass('btn-success');
                  $("#generic-modal-ok-{{$newRepoModalID}}").off('click');
                  $("#generic-modal-ok-{{$newRepoModalID}}").click(function () {
                    $('#generic-modal-{{$newRepoModalID}}').modal('hide');
                    if(confirm('Repo installed. Click OK to refresh page.')) {
                      location.reload();
                    }
                  });
                  $('#generic-modal-{{$newRepoModalID}}').modal();
              
                } else {
                    window.console.log('Error installing repo :' + response['message']);
                    alert('Error installing addon repo!');
                }
                return false;
            },
        'json');
  }
  function updateAddonRepo(repoName) {
    if(confirm('Are you sure you want to update the addon repo ' + repoName + '?')) {
      $.post(
        "/admin/plugins/updaterepo", {repoName: repoName}, 
            function(response) {
                if (response.success) {
                  window.console.log('Addon repo '+repoName+' successfully updated :' + response['message']);
                  //alert('Addon repo updated.');
				  $('#update-message-' + repoName).css('background-color', 'yellow');
				  $('#update-message-' + repoName).html('Repo updated!');
				  setTimeout(function () {
					  $('#update-message-' + repoName).html('');
				  }, 60000);
                } else {
                  window.console.log('Error updating repo :' + response['message']);
                  //alert('Error updating addon repo!');
				  $('#update-message-' + repoName).css('background-color', 'red');
				  $('#update-message-' + repoName).html('Error updating repo!');
				  setTimeout(function () {
					  $('#update-message-' + repoName).html('');
				  }, 60000);
                }
                return false;
            },
        'json');
    }
  }
  function switchAddonRepoBranch(repoName) {
    window.console.log('switchAddonRepoBranch: ' + repoName);
    // TODO: Discover the available branches and create an interface to switch between them
  }
  
  function removeAddonRepo(repoName) {
    // TODO: Unlink the addons
    if(confirm('Are you sure you want to remove the addon repo ' + repoName + '?')) {
      $.post(
        "/admin/plugins/removerepo", {repoName: repoName}, 
            function(response) {
                if (response.success) {
                  window.console.log('Addon repo '+repoName+' successfully removed :' + response['message']);
                  if(confirm('Repo deleted. Click OK to refresh page.')) {
                    location.reload();
                  }
                } else {
                  window.console.log('Error removing repo :' + response['message']);
                  alert('Error removing addon repo!');
                }
                return false;
            },
        'json');
    }
  }  
  
</script>