[Kimchi-devel] [PATCH 6/7] Repository Management - Edit Repository Support

Adam King rak at linux.vnet.ibm.com
Tue Mar 25 18:18:11 UTC 2014


From: Hongliang Wang <hlwang at linux.vnet.ibm.com>

Edit repository support.

Signed-off-by: Hongliang Wang <hlwang at linux.vnet.ibm.com>
Signed-off-by: Adam King <rak at linux.vnet.ibm.com>
---
 ui/css/theme-default/repository-edit.css |  87 +++++++++++++++++++++++
 ui/js/src/kimchi.repository_edit_main.js |  94 +++++++++++++++++++++++++
 ui/pages/repository-edit.html.tmpl       | 115 +++++++++++++++++++++++++++++++
 3 files changed, 296 insertions(+)
 create mode 100644 ui/css/theme-default/repository-edit.css
 create mode 100644 ui/js/src/kimchi.repository_edit_main.js
 create mode 100644 ui/pages/repository-edit.html.tmpl

diff --git a/ui/css/theme-default/repository-edit.css b/ui/css/theme-default/repository-edit.css
new file mode 100644
index 0000000..fd6d711
--- /dev/null
+++ b/ui/css/theme-default/repository-edit.css
@@ -0,0 +1,87 @@
+/*
+ * Project Kimchi
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Hongliang Wang <hlwang at linux.vnet.ibm.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#repository-edit-window {
+    height: 680px;
+    width: 1000px;
+}
+
+.repository-edit-fieldset {
+    float: left;
+    padding: 1em;
+    width: 95%;
+}
+
+.repository-edit-wrapper-label, .repository-edit-wrapper-controls {
+    display: inline-block;
+    height: 38px;
+    line-height: 38px;
+    margin-top: 5px;
+    vertical-align: top;
+}
+
+.repository-edit-wrapper-label {
+    width: 150px;
+}
+
+.repository-edit-wrapper-controls label {
+    vertical-align: middle;
+}
+
+.repository-edit-wrapper-controls {
+    width: 100%;
+}
+
+.repository-edit-wrapper-controls input[type="text"] {
+    font-size: 16px;
+    height: 38px;
+    line-height: 38px;
+    background: #fff;
+    -webkit-border-radius: 5px;
+    border-radius: 5px;
+    box-shadow: 2px 2px 2px #eee inset;
+    border-top: 1px solid #bbb;
+    border-left: 1px solid #bbb;
+    padding: 0 10px;
+    width: 100%;
+}
+
+
+.repository-edit-wrapper-controls input[type="text"][readonly] {
+    color: #bbb;
+    background-color: #fafafa;
+}
+
+
+.repository-edit-wrapper-controls input[type="text"][disabled] {
+    color: #bbb;
+    background-color: #fafafa;
+    cursor: not-allowed;
+}
+
+
+.deb .yum{
+    display: none;
+}
+
+
+.yum .deb{
+    display: none;
+}
diff --git a/ui/js/src/kimchi.repository_edit_main.js b/ui/js/src/kimchi.repository_edit_main.js
new file mode 100644
index 0000000..13af36c
--- /dev/null
+++ b/ui/js/src/kimchi.repository_edit_main.js
@@ -0,0 +1,94 @@
+/*
+ * Project Kimchi
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+kimchi.repository_fillForm = function(form, name, values) {
+    var name= (name=="" || !name) ? "%s" : name;
+    for(var prop in values) {
+        if ((typeof(values[prop])==="object") && !Array.isArray(values[prop])) {
+            tmpName=name.replace("%s", prop+"[%s]" );
+            kimchi.repository_fillForm(form, tmpName, values[prop]);
+        }
+        else {
+            tmpName=name.replace("%s", prop );
+            var control = $('input[name="' + tmpName + '"]', form);
+            switch($(control).attr('type')) {
+            case 'text':
+                $(control).val(values[prop]);
+                break;
+            case 'radio':
+            case 'checkbox':
+                $(control).each(function(i, c) {
+                    var matched = ('' + values[prop]) == $(c).val();
+                    $(c).prop('checked', matched);
+                });
+                break;
+            default:
+                break;
+            }
+        }
+    }    
+}
+
+kimchi.repository_edit_main = function() {
+
+    var editForm = $('#form-repository-edit');
+    
+    var saveButton = $('#repository-edit-button-save');
+
+    if(kimchi.host.capabilities['repo_mngt_tool']=="yum") {
+        editForm.find('input.deb').prop('disabled', true);
+    }
+    else if(kimchi.host.capabilities['repo_mngt_tool']=="deb") {
+        editForm.find('input.yum').prop('disabled', true);
+    }
+
+    kimchi.retrieveRepository(kimchi.selectedRepository, function(repository) {
+        kimchi.repository_fillForm(editForm,"",repository);
+        
+        $('input', editForm).on('input propertychange', function(event) {
+            if($(this).val() !== '') {
+                $(saveButton).prop('disabled', false);
+            }
+        });
+    });
+
+
+    var editRepository = function(event) {
+        var formData = $(editForm).serializeObject();
+        
+        if (formData && formData.config) {
+            formData.config.gpgcheck=(String(formData.config.gpgcheck).toLowerCase() === 'true');
+        }
+ 
+        kimchi.updateRepository(kimchi.selectedRepository, formData, function() {
+            kimchi.topic('kimchi/repositoryUpdated').publish();
+            kimchi.window.close();
+        }, function(jqXHR, textStatus, errorThrown) {
+            var reason = jqXHR &&
+                jqXHR['responseJSON'] &&
+                jqXHR['responseJSON']['reason'];
+            reason = reason ? ': ' + reason : '';
+            kimchi.message.error(i18n['KCHREPO6015M'] + reason);
+        });
+
+        return false;
+    };
+
+    $(editForm).on('submit', editRepository);
+    $(saveButton).on('click', editRepository);
+};
diff --git a/ui/pages/repository-edit.html.tmpl b/ui/pages/repository-edit.html.tmpl
new file mode 100644
index 0000000..7a893eb
--- /dev/null
+++ b/ui/pages/repository-edit.html.tmpl
@@ -0,0 +1,115 @@
+#*
+ * Project Kimchi
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *#
+#unicode UTF-8
+#import gettext
+#from kimchi.cachebust import href
+#silent t = gettext.translation($lang.domain, $lang.localedir, languages=$lang.lang)
+#silent _ = t.gettext
+#silent _t = t.gettext
+
+<div id="repository-edit-window" class="window">
+    <form id="form-repository-edit">
+        <header>
+            <h1 class="title">$_("Edit Repository")</h1>
+            <div class="close">X</div>
+        </header>
+        <div class="content">
+            <section id="form-repository-edit">
+                <fieldset class="repository-edit-fieldset">
+                    <div class="repository-id yum">
+                        <div class="repository-edit-wrapper-label">
+                            <label for="repository-edit-id-textbox">$_("ID")</label>
+                        </div>
+                        <div class="repository-edit-wrapper-controls">
+                            <input id="repository-edit-id-textbox" name="repo_id" type="text" disabled="disabled" readonly="readonly"/>
+                        </div>
+                    </div>
+                    <div class="repository-name yum">
+                        <div class="repository-edit-wrapper-label">
+                            <label for="repository-edit-name-textbox">$_("Name")</label>
+                        </div>
+                        <div class="repository-edit-wrapper-controls">
+                            <input id="repository-edit-name-textbox" class="yum" name="config[repo_name]" type="text" />
+                        </div>
+                    </div>
+                    <div class="repository-dist deb">
+                        <div class="repository-edit-wrapper-label">
+                            <label for="repository-edit-urlargs-textbox">$_("Distribution")</label>
+                        </div>
+                        <div class="repository-edit-wrapper-controls">
+                            <input id="repository-edit-urlargs-textbox" class="deb" name="config[dist]" type="text" />
+                        </div>
+                    </div> 
+                    <div class="repository-url">
+                        <div class="repository-edit-wrapper-label">
+                            <label for="repository-edit-baseurl-textbox">$_("URL")</label>
+                        </div>
+                        <div class="repository-edit-wrapper-controls">
+                            <input id="repository-edit-baseurl-textbox" name="baseurl" type="text" />
+                        </div>
+                    </div>
+                    <div class="repository-mirrorlist yum">
+                        <div class="repository-edit-wrapper-label">
+                            <label for="repository-edit-urlargs-textbox">$_("Mirror List URL")</label>
+                        </div>
+                        <div class="repository-edit-wrapper-controls">
+                            <input id="repository-edit-urlargs-textbox" class="yum" name="config[mirrorlist]" type="text" />
+                        </div>
+                    </div>
+                    <div class="repository-comps deb">
+                        <div class="repository-edit-wrapper-label">
+                            <label for="repository-edit-urlargs-textbox">$_("Components")</label>
+                        </div>
+                        <div class="repository-edit-wrapper-controls">
+                            <input id="repository-edit-urlargs-textbox" class="deb" name="config[comps]" type="text" />
+                        </div>
+                    </div>
+                    <div class="repository-gpgkey yum">
+                        <div class="repository-edit-wrapper-label">
+                            <label for="repository-edit-gpgkey-textbox">$_("GPG Key")</label>
+                        </div>
+                        <div class="repository-edit-wrapper-controls">
+                            <input id="repository-edit-gpgkey-textbox" class="yum" name="config[gpgkey]" type="text" />
+                        </div>
+                    </div>
+                    <div class="repository-gpgcheck yum">
+                        <div class="repository-edit-wrapper-label">
+                            <label>$_("GPG Check")</label>
+                        </div>
+                        <div class="repository-edit-wrapper-controls">
+                            <input id="repository-edit-gpgcheck-radio-true" class="yum" name="config[gpgcheck]" type="radio" value="true" />
+                            <label for="repository-edit-gpgcheck-radio-true">$_("Yes")</label>
+                            <input id="repository-edit-gpgcheck-radio-false" class="yum" name="config[gpgcheck]" type="radio" value="false" />
+                            <label for="repository-edit-gpgcheck-radio-false">$_("No")</label>
+                        </div>
+                    </div>
+                </fieldset>
+            </section>
+        </div>
+        <footer>
+            <div class="btn-group">
+                <button type="submit id="repository-edit-button-save" class="btn-normal">
+                    <span class="text">$_("Save")</span>
+                </button>
+            </div>
+        </footer>
+    </form>
+</div>
+<script type="text/javascript">
+    kimchi.repository_edit_main();
+</script>
-- 
1.8.1.4




More information about the Kimchi-devel mailing list