Univention Bugzilla – Attachment 3817 Details for
Bug 22902
UMC2: Druckeradministration
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Funktionen für Quota ergänzt
univention-printserver-2011_11_17.patch (text/plain), 26.55 KB, created by
Frank Greif
on 2011-11-17 14:33 CET
(
hide
)
Description:
Funktionen für Quota ergänzt
Filename:
MIME Type:
Creator:
Frank Greif
Created:
2011-11-17 14:33 CET
Size:
26.55 KB
patch
obsolete
>Index: debian/control >=================================================================== >--- debian/control (revision 5030) >+++ debian/control (working copy) >@@ -16,6 +16,7 @@ > foomatic-db > Standards-Version: 3.8.2 > >+ > Package: univention-printserver > Architecture: all > Depends: ${misc:Depends}, ${python:Depends}, >Index: umc/python/printers/de.po >=================================================================== >--- umc/python/printers/de.po (revision 5030) >+++ umc/python/printers/de.po (working copy) >@@ -4,10 +4,10 @@ > "Project-Id-Version: univention-management-console-module-printers\n" > "Report-Msgid-Bugs-To: packages@univention.de\n" > "POT-Creation-Date: 2011-11-07 12:45+0100\n" >-"PO-Revision-Date: 2011-11-09 20:20+0100\n" >-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" >+"PO-Revision-Date: 2011-11-17 14:18+0100\n" >+"Last-Translator: Frank Greif <fg@it25.de>\n" > "Language-Team: LANGUAGE <LL@li.org>\n" >-"Language: \n" >+"Language: de\n" > "MIME-Version: 1.0\n" > "Content-Type: text/plain; charset=UTF-8\n" > "Content-Transfer-Encoding: 8bit\n" >Index: umc/python/printers/__init__.py >=================================================================== >--- umc/python/printers/__init__.py (revision 5030) >+++ umc/python/printers/__init__.py (working copy) >@@ -38,6 +38,7 @@ > import univention.config_registry > > from fnmatch import * >+from time import sleep > import re > import string > import subprocess >@@ -107,7 +108,7 @@ > > self.finished(request.id,result) > >- def get(self,request): >+ def get_printer(self,request): > """ gets detail data for one printer. """ > > # ----------- DEBUG ----------------- >@@ -145,7 +146,8 @@ > MODULE.info(" << %s" % s) > # ----------------------------------- > >- result = self._job_list(request.options.get('printer','')) >+ printer = request.options.get('printer','') >+ result = self._job_list(printer) > > # ---------- DEBUG -------------- > MODULE.info("printers/jobs/query returns:") >@@ -166,13 +168,118 @@ > def list_quota(self,request): > """ lists all quota entries related to this printer. """ > >- # fill a dummy result table. >+ # ----------- DEBUG ----------------- >+ MODULE.info("printers/quota/query invoked with:") >+ pp = pprint.PrettyPrinter(indent=4) >+ st = pp.pformat(request.options).split("\n") >+ for s in st: >+ MODULE.info(" << %s" % s) >+ # ----------------------------------- >+ > printer = request.options.get('printer','') >+ > result = [] >+ >+ (stdout,stderr,status) = self._shell_command(['/usr/bin/pkusers','--list'],{'LANG':'C'}) >+ users = [] >+ expr = re.compile('^\s*(.*?)\s+\-\s\<') >+ if status == 0: >+ for line in stdout.split("\n"): >+ match = expr.match(line) >+ if match: >+ users.append(match.group(1)) >+ >+ result = [] >+ for user in users: >+ (stdout,stderr,status) = self._shell_command(['/usr/bin/repykota','-P',printer,user],{'LANG':'C'}) >+ if status == 0: >+ for line in stdout.split("\n"): >+ data = line[16:].split() # ignore possibly truncated user name >+ if len(data) >= 7: >+ ok = True >+ for n in (2,3,4,len(data)-3): >+ if not data[n].isdigit(): >+ ok = False >+ if ok: >+ MODULE.info(" -> user='%s' used=%s soft=%s hard=%s total=%s" % (user,data[2],data[3],data[4],data[len(data)-3])) >+ entry = { >+ 'user': user, >+ 'used': data[2], >+ 'soft': data[3], >+ 'hard': data[4], >+ 'total': data[len(data)-3] >+ } >+ result.append(entry) > >+ # ---------- DEBUG -------------- >+ MODULE.info("printers/quota/query returns:") >+ pp = pprint.PrettyPrinter(indent=4) >+ st = '' >+ if len(result) > 5: >+ tmp = result[0:5] >+ MODULE.info(" >> %d entries, first 5 are:" % len(result)) >+ st = pp.pformat(tmp).split("\n") >+ else: >+ st = pp.pformat(result).split("\n") >+ for s in st: >+ MODULE.info(" >> %s" % s) >+ # -------------------------------- >+ > self.finished(request.id,result) > >- def enable(self,request): >+ def list_users(self,request): >+ """ convenience function for the username entry. Lists >+ all user names. We don't return this as an array of {id,label} >+ tuples because: >+ >+ (1) id and label are always the same here >+ (2) at the frontend, we must do some postprocessing, and an array >+ is easier to handle. >+ (3) the ComboBox is able to handle a plain array. >+ """ >+ >+ # ----------- DEBUG ----------------- >+ MODULE.info("printers/users/query invoked with:") >+ pp = pprint.PrettyPrinter(indent=4) >+ st = pp.pformat(request.options).split("\n") >+ for s in st: >+ MODULE.info(" << %s" % s) >+ # ----------------------------------- >+ >+ result = [] >+ expr = re.compile('^\s*username:\s*(.*?)\s*$') >+ (stdout,stderr,status) = self._shell_command(['/usr/sbin/univention-directory-manager','users/user','list'],{'LANG':'C'}) >+ if status == 0: >+ for line in stdout.split("\n"): >+ match = expr.match(line) >+ if match: >+ MODULE.warn(" -> %s" % match.group(1)) >+ result.append(match.group(1)) >+ >+ # simulate 10000 more users >+ for g in range(0,100): >+ gn = 'group %d' % g >+ for u in range(0,100): >+ un = 'user %d' % u >+ result.append('%s in %s' % (un,gn)) >+ >+ # ---------- DEBUG -------------- >+ MODULE.info("printers/users/query returns:") >+ pp = pprint.PrettyPrinter(indent=4) >+ st = '' >+ if len(result) > 5: >+ tmp = result[0:5] >+ MODULE.info(" >> %d entries, first 5 are:" % len(result)) >+ st = pp.pformat(tmp).split("\n") >+ else: >+ st = pp.pformat(result).split("\n") >+ for s in st: >+ MODULE.info(" >> %s" % s) >+ # -------------------------------- >+ >+ self.finished(request.id,result) >+ >+ def enable_printer(self,request): > """ can enable or disable a printer, depending on args. > returns empty string on success, else error message. > """ >@@ -200,7 +307,7 @@ > > self.finished(request.id, result) > >- def cancel(self,request): >+ def cancel_jobs(self,request): > """ cancels one or more print jobs. Job IDs are passed > as an array that can be directly passed on to the > _shell_command() method >@@ -228,8 +335,69 @@ > > self.finished(request.id, result) > >+ >+ def set_quota(self,request): >+ """ sets quota limits for a (printer,user) combination. >+ optionally tries to create the corresponding user entry. >+ """ >+ >+ # ----------- DEBUG ----------------- >+ MODULE.info("printers/quota/set invoked with:") >+ pp = pprint.PrettyPrinter(indent=4) >+ st = pp.pformat(request.options).split("\n") >+ for s in st: >+ MODULE.info(" << %s" % s) >+ # ----------------------------------- >+ >+ printer = request.options.get('printer','') >+ user = request.options.get('user','') >+ soft = request.options.get('soft',0) >+ hard = request.options.get('hard',0) > >+ if printer=='' or user=='': >+ result = "Required parameter missing" >+ else: >+ result = self._set_quota(printer,user,soft,hard) > >+ # ---------- DEBUG -------------- >+ MODULE.info("printers/quota/set returns:") >+ pp = pprint.PrettyPrinter(indent=4) >+ st = pp.pformat(result).split("\n") >+ for s in st: >+ MODULE.info(" >> %s" % s) >+ # -------------------------------- >+ >+ self.finished(request.id, result) >+ >+ >+ def reset_quota(self,request): >+ """ resets quota for a (printer,user) combination. >+ """ >+ >+ # ----------- DEBUG ----------------- >+ MODULE.info("printers/quota/reset invoked with:") >+ pp = pprint.PrettyPrinter(indent=4) >+ st = pp.pformat(request.options).split("\n") >+ for s in st: >+ MODULE.info(" << %s" % s) >+ # ----------------------------------- >+ >+ printer = request.options.get('printer','') >+ users = request.options.get('users',[]) >+ >+ result = self._reset_quota(printer,users) >+ >+ # ---------- DEBUG -------------- >+ MODULE.info("printers/quota/reset returns:") >+ pp = pprint.PrettyPrinter(indent=4) >+ st = pp.pformat(result).split("\n") >+ for s in st: >+ MODULE.info(" >> %s" % s) >+ # -------------------------------- >+ >+ self.finished(request.id, result) >+ >+ > # ----------------------- Internal functions ------------------------- > > def _job_list(self,printer): >@@ -317,6 +485,48 @@ > > return '' > >+ def _set_quota(self,printer,user,soft,hard): >+ """ sets a quota entry. Can also add a user """ >+ >+ # Before we can set quota we have to ensure that the user is >+ # already known to PyKota. Fortunately these tools don't complain >+ # if we try to create a user that doesn't already exist. >+ >+ self._shell_command(['/usr/bin/pkusers','--skipexisting','--add',user],{'LANG':'C'}) >+ >+ # Caution! order of args is important! >+ >+ (stdout,stderr,status) = self._shell_command([ >+ '/usr/bin/edpykota', >+ '--printer',printer, >+ '--softlimit',str(soft), >+ '--hardlimit',str(hard), >+ '--add',user >+ ],{'LANG':'C'}) >+ >+ # not all errors are propagated in exit codes... >+ # but at least they adhere to the general rule that >+ # progress is printed to STDOUT and errors/warnings to STDERR >+ if status or len(stderr): >+ return stderr >+ >+ return '' >+ >+ def _reset_quota(self,printer,users): >+ """ resets the 'used' counter on a quota entry. """ >+ >+ cmd = [ '/usr/bin/edpykota','--printer',printer,'--reset' ] >+ # appending user names to the args array -> spaces in user names >+ # don't confuse edpykota (In 2.4, this was a problem) >+ for user in users: >+ cmd.append(user) >+ (stdout,stderr,status) = self._shell_command(cmd,{'LANG':'C'}) >+ >+ if status or len(stderr): >+ return stderr >+ >+ return '' >+ > def _quota_enabled(self,printer=None): > """ returns a dictionary with printer names and their 'quota active' status. > if printer is specified, returns only quota status for this printer. >@@ -363,4 +573,4 @@ > outputs = proc.communicate() > > return (outputs[0],outputs[1],proc.returncode) >- >\ No newline at end of file >+ >Index: umc/printers.xml >=================================================================== >--- umc/printers.xml (revision 5030) >+++ umc/printers.xml (working copy) >@@ -9,11 +9,11 @@ > > <command name="printers/query" function="list_printers"/> > >- <command name="printers/get" function="get"> >+ <command name="printers/get" function="get_printer"> > <attribute name="printer" syntax="String"/> > </command> > >- <command name="printers/enable" function="enable"> >+ <command name="printers/enable" function="enable_printer"> > <attribute name="printer" syntax="String"/> > <attribute name="on" syntax="Bool"/> > </command> >@@ -22,7 +22,7 @@ > <attribute name="printer" syntax="String"/> > </command> > >- <command name="printers/jobs/cancel" function="cancel"> >+ <command name="printers/jobs/cancel" function="cancel_jobs"> > <attribute name="printer" syntax="String"/> > <attribute name="jobs" syntax="String"/> > </command> >@@ -31,5 +31,23 @@ > <attribute name="printer" syntax="String"/> > </command> > >+ <command name="printers/users/query" function="list_users"/> >+ >+ <!-- equally used to add or to edit an entry --> >+ <command name="printers/quota/set" function="set_quota"> >+ <attribute name="printer" syntax="String"/> >+ <attribute name="user" syntax="String"/> >+ <attribute name="soft" syntax="Integer"/> >+ <attribute name="hard" syntax="Integer"/> >+ </command> >+ >+ <!-- how about deleting an entry? --> >+ >+ <!-- seperate call: reset 'used' counter --> >+ <command name="printers/quota/reset" function="reset_quota"> >+ <attribute name="printer" syntax="String"/> >+ <attribute name="users" syntax="Array"/> >+ </command> >+ > </module> > </umc> >Index: umc/icons/50x50/printing.png >=================================================================== >Cannot display: file marked as a binary type. >svn:mime-type = application/octet-stream > >Property changes on: umc/icons/50x50/printing.png >___________________________________________________________________ >Added: svn:mime-type > + application/octet-stream > >Index: umc/icons/16x16/printing.png >=================================================================== >Cannot display: file marked as a binary type. >svn:mime-type = application/octet-stream > >Property changes on: umc/icons/16x16/printing.png >___________________________________________________________________ >Added: svn:mime-type > + application/octet-stream > >Index: umc/icons/scalable/printing.svgz >=================================================================== >Cannot display: file marked as a binary type. >svn:mime-type = application/octet-stream > >Property changes on: umc/icons/scalable/printing.svgz >___________________________________________________________________ >Added: svn:mime-type > + application/octet-stream > >Index: umc/js/de.po >=================================================================== >--- umc/js/de.po (revision 5030) >+++ umc/js/de.po (working copy) >@@ -3,16 +3,17 @@ > msgstr "" > "Project-Id-Version: univention-management-console-module-printers\n" > "Report-Msgid-Bugs-To: packages@univention.de\n" >-"POT-Creation-Date: 2011-11-09 17:57+0100\n" >-"PO-Revision-Date: 2011-11-09 20:20+0100\n" >-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" >+"POT-Creation-Date: 2011-11-17 12:15+0100\n" >+"PO-Revision-Date: 2011-11-17 14:28+0100\n" >+"Last-Translator: Frank Greif <fg@it25.de>\n" > "Language-Team: LANGUAGE <LL@li.org>\n" >-"Language: \n" >+"Language: de\n" > "MIME-Version: 1.0\n" > "Content-Type: text/plain; charset=UTF-8\n" > "Content-Transfer-Encoding: 8bit\n" > >-#: umc/js/_printers/DetailPage.js:59 umc/js/_printers/OverviewPage.js:133 >+#: umc/js/_printers/DetailPage.js:59 >+#: umc/js/_printers/OverviewPage.js:133 > msgid "Activate" > msgstr "Aktivieren" > >@@ -20,7 +21,15 @@ > msgid "Activate this printer" > msgstr "diesen Drucker aktivieren" > >-#: umc/js/_printers/QuotaPage.js:88 >+#: umc/js/_printers/QuotaPage.js:108 >+msgid "Add new record" >+msgstr "Eintrag hinzufügen" >+ >+#: umc/js/_printers/QuotaPage.js:227 >+msgid "Add quota entry" >+msgstr "Quota-Eintrag hinzufügen" >+ >+#: umc/js/_printers/QuotaPage.js:92 > msgid "Back" > msgstr "zurück" > >@@ -29,6 +38,7 @@ > msgstr "Zurück zur Ãbersicht" > > #: umc/js/_printers/DetailPage.js:129 >+#: umc/js/_printers/QuotaDialog.js:36 > msgid "Cancel" > msgstr "Abbrechen" > >@@ -36,11 +46,12 @@ > msgid "Cancel this job/these jobs" > msgstr "Diesen Druckauftrag (oder mehrere) abbrechen" > >-#: umc/js/_printers/QuotaPage.js:25 >+#: umc/js/_printers/QuotaPage.js:27 > msgid "Current quota records for printer" > msgstr "Aktuelle Quota-Einträge für diesen Drucker" > >-#: umc/js/_printers/DetailPage.js:71 umc/js/_printers/OverviewPage.js:151 >+#: umc/js/_printers/DetailPage.js:71 >+#: umc/js/_printers/OverviewPage.js:151 > msgid "Deactivate" > msgstr "Deaktivieren" > >@@ -48,7 +59,8 @@ > msgid "Deactivate this printer" > msgstr "diesen Drucker deaktivieren" > >-#: umc/js/_printers/DetailPage.js:232 umc/js/_printers/OverviewPage.js:53 >+#: umc/js/_printers/DetailPage.js:232 >+#: umc/js/_printers/OverviewPage.js:53 > #: umc/js/_printers/OverviewPage.js:118 > msgid "Description" > msgstr "Beschreibung" >@@ -57,19 +69,25 @@ > msgid "Details for printer <b>{printer}</b>" > msgstr "Details für Drucker <b>{printer}</b>" > >-#: umc/js/_printers/QuotaPage.js:81 >+#: umc/js/_printers/QuotaPage.js:84 > msgid "Edit" > msgstr "Bearbeiten" > >-#: umc/js/_printers/DetailPage.js:83 umc/js/_printers/OverviewPage.js:169 >+#: umc/js/_printers/DetailPage.js:83 >+#: umc/js/_printers/OverviewPage.js:169 > msgid "Edit quota" > msgstr "Quota bearbeiten" > >+#: umc/js/_printers/QuotaPage.js:240 >+msgid "Edit quota entry" >+msgstr "Quota bearbeiten" >+ > #: umc/js/_printers/DetailPage.js:84 > msgid "Edit quota related to this printer" > msgstr "Quota-Einträge für diesen Drucker bearbeiten" > >-#: umc/js/_printers/QuotaPage.js:63 >+#: umc/js/_printers/QuotaPage.js:65 >+#: umc/js/_printers/QuotaDialog.js:71 > msgid "Hard limit" > msgstr "Hard limit" > >@@ -77,11 +95,12 @@ > msgid "Job" > msgstr "Druckauftrag" > >-#: umc/js/_printers/QuotaPage.js:67 >+#: umc/js/_printers/QuotaPage.js:69 > msgid "Lifetime page counter" > msgstr "Seitenzähler" > >-#: umc/js/_printers/DetailPage.js:231 umc/js/_printers/OverviewPage.js:54 >+#: umc/js/_printers/DetailPage.js:231 >+#: umc/js/_printers/OverviewPage.js:54 > #: umc/js/_printers/OverviewPage.js:114 > msgid "Location" > msgstr "Ort" >@@ -90,7 +109,7 @@ > msgid "Owner" > msgstr "Eigentümer" > >-#: umc/js/_printers/QuotaPage.js:55 >+#: umc/js/_printers/QuotaPage.js:57 > msgid "Pages used" > msgstr "gedruckte Seiten" > >@@ -102,31 +121,36 @@ > msgid "Printer" > msgstr "Drucker" > >-#: umc/js/_printers/OverviewPage.js:29 umc/js/_printers/OverviewPage.js:40 >+#: umc/js/_printers/OverviewPage.js:29 >+#: umc/js/_printers/OverviewPage.js:40 > msgid "Printer administration" > msgstr "Druckerverwaltung" > >-#: umc/js/_printers/DetailPage.js:27 umc/js/_printers/DetailPage.js:38 >+#: umc/js/_printers/DetailPage.js:27 >+#: umc/js/_printers/DetailPage.js:38 > msgid "Printer details" > msgstr "Druckerdetails" > > #: umc/js/_printers/OverviewPage.js:52 >+#: umc/js/_printers/QuotaDialog.js:49 > msgid "Printer name" > msgstr "Druckername" > >-#: umc/js/_printers/QuotaPage.js:26 umc/js/_printers/QuotaPage.js:37 >+#: umc/js/_printers/QuotaPage.js:28 >+#: umc/js/_printers/QuotaPage.js:39 > msgid "Printer quota" > msgstr "Druckername" > >-#: umc/js/_printers/DetailPage.js:229 umc/js/_printers/OverviewPage.js:103 >+#: umc/js/_printers/DetailPage.js:229 >+#: umc/js/_printers/OverviewPage.js:103 > msgid "Quota" > msgstr "Quota" > >-#: umc/js/_printers/QuotaPage.js:131 >+#: umc/js/_printers/QuotaPage.js:174 > msgid "Quota entries for printer <b>{printer}</b>" > msgstr "Quota-Einträge für Drucker <b>{printer}</b>" > >-#: umc/js/_printers/QuotaPage.js:96 >+#: umc/js/_printers/QuotaPage.js:100 > msgid "Refresh" > msgstr "Aktualisieren" > >@@ -138,15 +162,20 @@ > msgid "Refresh printer list" > msgstr "Drucker-Liste aktualisieren" > >-#: umc/js/_printers/QuotaPage.js:74 >+#: umc/js/_printers/QuotaPage.js:76 > msgid "Reset user quota" > msgstr "Quota für diesen Nutzer zurücksetzen" > >+#: umc/js/_printers/QuotaDialog.js:29 >+msgid "Save changes" >+msgstr "Eintrag speichern" >+ > #: umc/js/_printers/OverviewPage.js:50 > msgid "Search key" > msgstr "Suchbegriff" > >-#: umc/js/_printers/DetailPage.js:224 umc/js/_printers/OverviewPage.js:80 >+#: umc/js/_printers/DetailPage.js:224 >+#: umc/js/_printers/OverviewPage.js:80 > msgid "Server" > msgstr "Server" > >@@ -154,11 +183,13 @@ > msgid "Size" > msgstr "GröÃe" > >-#: umc/js/_printers/QuotaPage.js:59 >+#: umc/js/_printers/QuotaPage.js:61 >+#: umc/js/_printers/QuotaDialog.js:64 > msgid "Soft limit" > msgstr "Soft limit" > >-#: umc/js/_printers/DetailPage.js:225 umc/js/_printers/OverviewPage.js:88 >+#: umc/js/_printers/DetailPage.js:225 >+#: umc/js/_printers/OverviewPage.js:88 > msgid "Status" > msgstr "Status" > >@@ -168,14 +199,17 @@ > > #: umc/js/_printers/OverviewPage.js:28 > msgid "This module lets you manage the printers defined on your machine" >-msgstr "" >-"In diesem Modul können Sie die Drucker verwalten, die auf Ihrer Maschine " >+msgstr "In diesem Modul können Sie die Drucker verwalten, die auf Ihrer Maschine " > "definiert sind." > >-#: umc/js/_printers/QuotaPage.js:51 >+#: umc/js/_printers/QuotaPage.js:53 > msgid "User" > msgstr "Nutzer" > >+#: umc/js/_printers/QuotaDialog.js:55 >+msgid "User name" >+msgstr "Nutzername" >+ > #: umc/js/_printers/OverviewPage.js:125 > msgid "View details" > msgstr "Details ansehen" >@@ -185,21 +219,25 @@ > "You see the details of this printer and its print jobs. You can activate/" > "deactivate the printer, edit its quota definitions if quota is enabled, and " > "cancel print jobs." >-msgstr "" >-"Sie sehen die Details des Druckers sowie seine aktuellen Druckaufträge. Sie " >+msgstr "Sie sehen die Details des Druckers sowie seine aktuellen Druckaufträge. Sie " > "können den Drucker aktivieren/deaktivieren, Quota-Einträge verwalten und " > "Druckaufträge abbrechen." > >-#: umc/js/_printers/DetailPage.js:218 umc/js/_printers/DetailPage.js:229 >-#: umc/js/_printers/OverviewPage.js:95 umc/js/_printers/OverviewPage.js:107 >+#: umc/js/_printers/DetailPage.js:218 >+#: umc/js/_printers/DetailPage.js:229 >+#: umc/js/_printers/OverviewPage.js:95 >+#: umc/js/_printers/OverviewPage.js:107 > msgid "active" > msgstr "aktiv" > >-#: umc/js/_printers/DetailPage.js:219 umc/js/_printers/OverviewPage.js:96 >+#: umc/js/_printers/DetailPage.js:219 >+#: umc/js/_printers/OverviewPage.js:96 > #: umc/js/_printers/OverviewPage.js:109 > msgid "inactive" > msgstr "inaktiv" > >-#: umc/js/_printers/DetailPage.js:215 umc/js/_printers/OverviewPage.js:98 >+#: umc/js/_printers/DetailPage.js:215 >+#: umc/js/_printers/OverviewPage.js:98 > msgid "unknown" > msgstr "unbekannt" >+ >Index: umc/js/_printers/QuotaPage.js >=================================================================== >--- umc/js/_printers/QuotaPage.js (revision 5030) >+++ umc/js/_printers/QuotaPage.js (working copy) >@@ -11,6 +11,8 @@ > dojo.require("umc.widgets.Grid"); > dojo.require("umc.widgets.Form"); > >+dojo.require("umc.modules._printers.QuotaDialog"); >+ > dojo.declare("umc.modules._printers.QuotaPage", > [ > umc.widgets.Page, >@@ -72,15 +74,17 @@ > { > name: 'clear', > label: this._("Reset user quota"), >- callback: dojo.hitch(this, function(ids) { >- // TODO do something useful here >+ isMultiAction: true, >+ callback: dojo.hitch(this, function(ids,values) { >+ this._reset_quota_entries(values); > }) > }, > { > name: 'edit', > label: this._("Edit"), >- callback: dojo.hitch(this, function(ids) { >- // TODO do something useful here >+ callback: dojo.hitch(this, function(ids,values) { >+ // always use the first value since multiselect doesn't make sense. >+ this._edit_quota_entry(values[0]); > }) > }, > { >@@ -98,6 +102,14 @@ > callback: dojo.hitch(this, function() { > this._refresh_view(); > }) >+ }, >+ { >+ name: 'add', >+ label: this._("Add new record"), >+ isContextAction: false, >+ callback: dojo.hitch(this, function(ids) { >+ this._add_quota_entry(); >+ }) > } > ]; > >@@ -110,6 +122,27 @@ > pane.addChild(this._grid); > > }, >+ >+ startup: function() { >+ >+ this.inherited(arguments); >+ >+ // fetch the userlist >+ umc.tools.umcpCommand('printers/users/query').then( >+ dojo.hitch(this, function(data) { >+ if (data.result.length) >+ { >+ // we keep this list unchanged; it will be fetched only once. >+ // on open of 'add quota' dialog, we pass a userlist that >+ // is cleaned up from users already having a quota entry. >+ this._userlist = data.result; >+ } >+ }), >+ dojo.hitch(this, function(data) { >+ umc.dialog.alert('Error fetching userlist: ' + data.message); >+ }) >+ ); >+ }, > > // Calling page passes args here. Arg is here the printer ID. > setArgs: function(args) { >@@ -119,11 +152,21 @@ > }, > > onHide: function() { >- // force clean state >+ >+ this.inherited(arguments); // do I need this? >+ >+ // on next show(), the previous content >+ // should not be visible anymore. > this._head.set('content',''); // clear header text > this._grid.filter(); // clear grid data > }, > >+ onShow: function() { >+ >+ this.inherited(arguments); // do I need this? >+ >+ }, >+ > // called when the page is shown, but can equally be called > // on a manual or automatic refresh. > _refresh_view: function() { >@@ -132,8 +175,155 @@ > > // read current quota list > this._grid.filter({printer:this._printer_id}); >+ >+ // on first open: create the child dialog where we can edit one quota entry. >+ if (! this._dialog) >+ { >+ this._dialog = new umc.modules._printers.QuotaDialog(); >+ >+ // listen to the events of the dialog >+ dojo.connect(this._dialog,'onSubmit',dojo.hitch(this, function(values) { >+ this._set_quota_entry(values); >+ })); >+// dojo.connect(this._dialog,'onCancel',dojo.hitch(this, function() { >+// // nothing to do here. >+// })); >+ >+ } >+ > }, > >+ // called from different places: the function that sets >+ // a quota entry. When called with soft=0 and hard=0 this >+ // would effectively forbid the user from printing... >+ _set_quota_entry: function(values) { >+ umc.tools.umcpCommand('printers/quota/set',values).then( >+ dojo.hitch(this,function(data) { >+ if (data.result) >+ { >+ // an error message from the edpykota tool >+ umc.dialog.alert(data.result); >+ } >+ else >+ { >+ // success -> refresh view. >+ this._refresh_view(); >+ } >+ }), >+ dojo.hitch(this,function(data) { >+ // error message from framework >+ umc.dialog.alert(data.message); >+ }) >+ ); >+ }, >+ >+ // prepares everything to add a new quota entry. >+ _add_quota_entry: function() { >+ this._dialog.setValues({ >+ printer: this._printer_id, >+ soft: null, >+ hard: null, >+ users: this._cleaned_userlist(), >+ title: this._("Add quota entry") >+ }); >+ this._dialog.show(); >+ }, >+ >+ // prepares the edit dialog and shows it. >+ // values is here a tuple of fields; this is always a single action. >+ _edit_quota_entry: function(values) { >+ >+ try >+ { >+ var val = { >+ printer: this._printer_id, >+ title: this._("Edit quota entry") >+ }; >+ this._dialog.setValues(dojo.mixin(val,values)); >+ this._dialog.show(); >+ } >+ catch(ex) >+ { >+ console.error('edit_quota_entry(): ' + ex.message); >+ } >+ }, >+ >+ // resets the 'used' counter on a list of users. >+ // values is the array of field tuples of those users. >+ _reset_quota_entries: function(values) { >+ >+ // if nothing is selected... why does the grid call the callback? >+ if (values.length == 0) >+ { >+ return; >+ } >+ >+ // ** NOTE ** we transfer the user names as an array since >+ // we can't know if some of them contain spaces or >+ // any other separator chars. >+ var users = []; >+ for (var u in values) >+ { >+ users.push(values[u]['user']); >+ } >+ >+ umc.tools.umcpCommand('printers/quota/reset',{ >+ printer: this._printer_id, >+ users: users >+ }).then( >+ dojo.hitch(this,function(data) { >+ if (data.result) >+ { >+ // an error message from the edpykota tool >+ umc.dialog.alert(data.result); >+ } >+ else >+ { >+ // success -> refresh view. >+ this._refresh_view(); >+ } >+ }), >+ dojo.hitch(this,function(data) { >+ // error message from framework >+ umc.dialog.alert(data.message); >+ }) >+ ); >+ }, >+ >+ // prepares the list of users eligible for adding a quota entry: >+ // this is the list of all users minus those that already have >+ // a quota entry for this printer. >+ // >+ // Will be called only directly before a 'add quota entry' dialog >+ // will be shown. >+ _cleaned_userlist: function() { >+ >+ var result = []; >+ var src = this._userlist; >+ >+ var usr = {}; // not an array: i want to to check for containedness! >+ var items = this._grid.getAllItems(); >+ for (var i in items) >+ { >+ var u = items[i]['user']; >+ usr[u] = u; >+ } >+ >+ for (var s in src) >+ { >+ var sitem = src[s]; >+ >+ // take this source item only if it is not contained >+ // in the 'usr' dict. >+ if (typeof(usr[sitem]) == 'undefined') >+ { >+ result.push(sitem); >+ } >+ } >+ >+ return result; >+ }, >+ > // main module listens here to return to the detail page > closeQuota: function(args) { > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
|
Diff
Attachments on
bug 22902
:
3770
| 3817 |
3842
|
3849
|
3916
|
3917